1 package bao4;
2 import java.util.*;
3 public class Jihe
4 {
5
6 public static void main(String[] args)
7 {
8
9 //<>表示泛型
10 //泛型不支持值类型
11 ArrayList<String> ls=new ArrayList<String>();
12 //追加数据
13 ls.add("aaa");
14 ls.add("bbb");
15 ls.add("ccc");
16 ls.add("fff");
17 //插入数据
18 ls.add(3, "ddd");
19 ls.add(4, "eee");
20 //集合长度
21 System.out.println("集合长度="+ls.size());
22 //取数据
23 System.out.println("集合数据是"+ls.get(0));
24 //移除数据
25 ls.remove(3);
26 //修改数据
27 ls.set(3, "www");
28 //查找
29 System.out.println("位置是"+ls.indexOf("www"));
30 //判断是否有某个数据
31 if(ls.contains("www"))
32 {
33 System.out.println("找到了");
34 }
35 else
36 {
37 System.out.println("没找到");
38 }
39 //清除全部数据
40 //ls.clear();
41 //遍历集合
42 for(String i:ls)
43 {
44 System.out.println(i);
45 }
46 }
47 }