public class ArrayList<E> {
public static final int DEFAULT_CAPACITY = 10;
private int size; // number of occupied space
private E[] data; // ArrayList, encapsulate with the private keyword
public ArrayList() {
this(DEFAULT_CAPACITY);
size = 0;
}
@SuppressWarnings("unchecked")
public ArrayList(int capacity) {
data = (E[])new Object[capacity];
size = 0;
if(capacity < 0) {
throw new IllegalArgumentException("Capacity should more than 0");
}
}
//Need to be fixed
//
//
//
public ArrayList(List<E> other) {
List<E> newList = new ArrayList<E>();
}
}
This is my code, and I made a constructor with the parameter( List other), the last one. I try to copy the list into the current array list; the E[] data, variable. But the error is List cannot copy the data to the E[]. So, I'm a little bit confused. How can I copy them? if I cannot How can I copy the List ?