Arraylist
底层实现是数组,查询块,增删慢。线程不安全,但是效率高
Vector
底层实现是数组,查询块,增删慢。线程安全,效率低。
LinkedList
底层实现是链表,查询慢,增删块,线程不安全,效率高
Arraylist
案例一:简单的存储及遍历,存储字符串
ArrayList array=new ArrayList(); array.add("hello"); array.add("csz"); array.add("lc"); Iterator it=array.iterator(); while (it.hasNext()) { String s=(String)it.next(); System.out.println(s); }
案例二:存储自定义对象Student
ArrayList array=new ArrayList(); Student s1=new Student(2,"鲤鱼"); Student s2=new Student(21,"陈书泽"); Student s3=new Student(23,"庄婷婷"); Student s4=new Student(26,"李四"); array.add(s1); array.add(s2); array.add(s3); array.add(s4); Iterator it=array.iterator(); while (it.hasNext()) { Student s=(Student)it.next(); System.out.println(s); } for (int i=0;i<array.size();i++) { Student s=(Student)array.get(i); System.out.println(s); }
时间: 2024-10-07 10:21:28