1 package ArrayList链表; 2 import java.util.*; 3 public class kk1 { 4 5 /** 6 * 作者:Mr.Fan 7 * 功能:记住ArrayList链表 8 */ 9 public static void main(String[] args) { 10 // TODO Auto-generated method stub 11 ArrayList al=new ArrayList(); 12 System.out.println("al大小:"+al.size()); 13 Clerk clerk1=new Clerk("宋江",50,1000); 14 Clerk clerk2=new Clerk("吴用",45,1200); 15 Clerk clerk3=new Clerk("林冲",45,1400); 16 al.add(clerk1); 17 al.add(clerk2); 18 al.add(clerk3); 19 System.out.println("al大小:"+al.size()); 20 for(int i=0;i<al.size();i++) 21 { 22 Clerk temp=(Clerk)al.get(i);//这里的i是指链表中的地址,指向 23 System.out.println("名字="+temp.getName()); 24 } 25 //删除一个对象 26 al.remove(1); 27 System.out.println("++++++++++++删除吴用++++++++++++++++++"); 28 for(int i=0;i<al.size();i++) 29 { 30 Clerk temp=(Clerk)al.get(i);//这里的i是指链表中的地址,指向 31 System.out.println("名字="+temp.getName()); 32 } 33 34 } 35 36 } 37 class Clerk 38 { 39 40 private String name; 41 private int age; 42 private float sal; 43 public Clerk(String name,int age,float sal) 44 { 45 this.name=name; 46 this.age=age; 47 this.sal=sal; 48 } 49 public String getName() { 50 return name; 51 } 52 public void setName(String name) { 53 this.name = name; 54 } 55 public int getAge() { 56 return age; 57 } 58 public void setAge(int age) { 59 this.age = age; 60 } 61 public float getSal() { 62 return sal; 63 } 64 public void setSal(float sal) { 65 this.sal = sal; 66 } 67 }