public class ArrayList implements List{ /** * 底层存储 */ private Object[]elementData; /** * 元素的数量 */ private int size; public ArrayList(){ this(10); } public ArrayList(int initialCapacity) throws IllegalArgumentException{ if(initialCapacity < 0) { throw new IllegalArgumentException("Illegal Capacity:"+ initialCapacity); } //初始化数组 this.elementData = new Object[initialCapacity]; } public int size(){ return this.size; } @Override public void set(int index, Object object) { } @Override public void clear() { } @Override public Object[] toArray() { return new Object[0]; } public boolean add(Object object){ int count = size; elementData[size++]= object; if(count < size){ return true; } return false; } @Override public void add(int index, Object object) { } @Override public void addAll(List list) { } @Override public void remove(int index) { } public Object get(int index){ return elementData[index]; }}
public class ArrayList implements List{
/**
* 底层存储
*/
private Object[]elementData;
/**
* 元素的数量
*/
private int size;
public ArrayList(){
this(10);
}
public ArrayList(int initialCapacity) throws IllegalArgumentException{
if(initialCapacity < 0) {
throw new IllegalArgumentException("Illegal Capacity:"+ initialCapacity);
}
//初始化数组
this.elementData = new Object[initialCapacity];
}
public int size(){
return this.size;
}
@Override
public void set(int index, Object object) {
}
@Override
public void clear() {
}
@Override
public Object[] toArray() {
return new Object[0];
}
public boolean add(Object object){
int count = size;
elementData[size++]= object;
if(count < size){
return true;
}
return false;
}
@Override
public void add(int index, Object object) {
}
@Override
public void addAll(List list) {
}
@Override
public void remove(int index) {
}
public Object get(int index){
return elementData[index];
}
}