码迷,mamicode.com
首页 > 其他好文 > 详细

超实用 1 ArrayList 链表

时间:2015-04-07 21:31:30      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

超实用 1 ArrayList 链表

标签:

原文地址:http://www.cnblogs.com/vip-fan1234xiang/p/4399342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!