프로그래밍/JAVA

ArrayList + Generic 구현하기

kkwonsy 2019. 2. 28. 23:28


제네릭을 활용한 ArrayList를 구현해보는 건 기본기를 닦는데 매우 도움이 되는 것 같다.

답안지는 저 아래에 있다. 

https://github.com/yudong80/ThinkDataStructures/blob/master/code/src/com/allendowney/thinkdast/MyArrayList.java





List 인터페이스를 implements 해서 직접 한번 구현해보자!!

public class MyArrayList<T> implements List<T> {

private int size;
private T[] array;

public MyArrayList() {
size = 0;
array = (T[])new Object[10];
}