-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList
More file actions
55 lines (49 loc) · 1.07 KB
/
ArrayList
File metadata and controls
55 lines (49 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ArrayList_Main;
import java.util.ArrayList;
public class Main {
/*
* @ArrayList集合类的用法
* @时间2017年5月21日
* @夏天
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建ArrayList对象al,做xc的泛型
ArrayList<xc> al=new ArrayList<xc>();
//创建xc的对象x
xc x=new xc("sl");
//创建xc的对象x1
xc x1=new xc("ss");
//al对象添加x
al.add(x);
//al对象添加x1
al.add(x1);
//输出al的哈希码
System.out.println(al.toString());
/*System.out.println(al.get(1));
System.out.println(al.get(2));*/
//输出al集合的长度
System.out.println(al.size());
//遍历al集合
for(int i=0;i<al.size();i++){
//做强转,使xc拥有al.get方法
xc tv=al.get(i);
//输出遍历
System.out.println(tv.getName());
}
System.out.println(al.getClass().getName());
}
}
class xc{
// private int age;
private String name;
xc(String name){
// this.age=age;
this.name=name;
}
// int getAge() {
// return age;
public String getName() {
return name;
}
}