集合框架01

一、集合

1.1 Collection接口

 3 import java.util.ArrayList;
 4 import java.util.Collection;
 5 
 6 public class Demo01 {
 7     /*
 8      * ArrayList implement List
 9      * List extends Collection
10      * Collection接口方法:
11      *             void clear();清空集合中的所有元素,容器本身依然存在
12      *             boolean contains(Object o);判断对象是否存在集合中
13      *             Object[] toArray();集合中的所有元素,转换成一个数组中的元素
14      *             remove();移除集合中指定的元素
15      */
16     
17     public static void main(String[] args) {
18         function_3();
19     }
20     
21 
22 
23 
24     public static void function(){
25         Collection<String> col = new ArrayList<>();
26         col.add("abc");
27         col.add("bcd");
28         System.out.println(col);
29         
30         col.clear();
31         System.out.println(col);
32     }
33     public static void function_1(){
34         Collection<String> col = new ArrayList<>();
35         col.add("abc");
36         col.add("bcd");
37         
38         System.out.println(col.contains("ac"));
39     }
40 
41     public static void function_2() {
42         Collection<String> col = new ArrayList<>();
43         col.add("abc");
44         col.add("bcd");
45         
46         Object[] o = col.toArray();
47         for(int i = 0; i<o.length; i++){
48             System.out.println(o[i]);
49         }
50     }
51     public static void function_3() {
52         Collection<String> col = new ArrayList<>();
53         col.add("abc");
54         col.add("bcd");
55         col.add("dasf");
56         System.out.println(col);
57         
58         if(col.remove("abc"))
59             System.out.println("删除成功");
60         else 
61             System.out.println("删除失败");
62         
63         System.out.println(col);
64     }
65 }

 

posted @ 2017-04-06 21:19  蒋酱酱  阅读(149)  评论(0编辑  收藏  举报