public class MyArrayList<P> {
private P[] dateArr = (P[])new Object[100];
private int count = 0;
public void add(P date) {
dateArr[count] = date;
count++;
}
public P get(int num) {
if (num >= 0 && num < count) {
return dateArr[num];
}else{
System.out.println("你给的索引"+num+"不存在");
return null;
}
}
public void set(int num, P num1) {
dateArr[num] = num1;
}
public boolean contains(P num) {
boolean flag = false;
for (int i = 0; i < dateArr.length; i++) {
if (dateArr[i] == num) {
flag = true;
break;
}
}
return flag;
}
public int size(){
return count;
}
public boolean isEmpty(){
boolean flag=false;
if(count==0){
flag=true;
}
return flag;
}
} |
|