首页 > 编程语言 > 详细

Java集合复习Collection

时间:2017-10-26 12:38:22      阅读:217      评论:0      收藏:0      [点我收藏+]
 1 import java.util.*;
 2 class Snow{}
 3 class Powder extends Snow{}
 4 class Crusty extends Snow{}
 5 class Slush extends Snow{}
 6 
 7 class Light extends Powder {}
 8 class Heavy extends Powder {}
 9 
10 
11 public class AddingGroups {
12 
13     public static void main(String[] args) {
14 
15         Collection<Integer> collection = new ArrayList<Integer>(Arrays.asList(1,2,3));
16         Integer[] moreInts = {4,5,6};
17         //Arrays.asList 顾名思义,传进去一个数组,搞出来一个List。数组转换为List
18         collection.addAll(Arrays.asList(moreInts));
19         Collections.addAll(collection, 7);//可变参数列表
20         
21         /* Arrays.asList()的底层实现是用数组,因此不能调整尺寸。所以运行时会出现UnsupportedOperationException
22         List list = Arrays.asList(1,2,3);
23         list.add(4);
24         System.out.println(list);
25         */
26         System.out.println(collection);
27         
28         List<Snow> snow1 = Arrays.asList(new Powder(),new Slush(),new Crusty());
29         
30         List<Snow> snow2 = Arrays.asList(new Light(),new Heavy());
31         
32 //        Collections.addAll(snow2);
33         
34         List<Snow> snow3 = new ArrayList<Snow>();
35         
36         Collections.addAll(snow3, new Light(),new Heavy());
37         
38         //显式类型参数说明
39         List<Snow> snow4 = Arrays.<Snow>asList(new Light(),new Heavy());
40         
41         
42     }
43 
44 }

 

Java集合复习Collection

原文:http://www.cnblogs.com/vector11248/p/7735806.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!