ArrayList
数组结构实现,查找块,增删慢
JDK1.2版本,运行效率快,线程不安全
使用方法
/*
Arraylist使用
存储结构:数组结构,查找块增删慢
*/
public class Demo02 {
public static void main(String[] args) {
//创建集合
ArrayList arrayList=new ArrayList();
Student s1=new Student("张三",15);
Student s2=new Student("李斯",16);
Student s3=new Student("王五",18);
arrayList.add(s1);
arrayList.add(s2);
arrayList.add(s3);
System.out.println(arrayList.toString());
//删除
arrayList.remove(new Student("张三",15));
System.out.println(arrayList.toString());
//遍历
Iterator it=arrayList.iterator();
while (it.hasNext()){
Student s=(Student)it.next();
System.out.println(s.toString());
}
ListIterator lit=arrayList.listIterator();
while (lit.hasPrevious()){
Student s=(Student)lit.previous();
System.out.println(s.toString());
}
//判断
System.out.println(arrayList.contains(new Student("李斯",16)));
//查找
System.out.println(arrayList.indexOf(s2));
}
}