码迷,mamicode.com
首页 > 编程语言 > 详细

Java Collection

时间:2016-04-18 10:12:34      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

Java Collection(集合)

技术分享

集合中的一些技巧:

通过Collections类的静态方法,可以对集合进行一些操作

技术分享
 1         java.util.List<Integer> numbers=Arrays.asList(12,5,6,8,11,4);
 2         Collections.sort(numbers);//排序
 3         System.out.println(numbers);
 4         Collections.reverse(numbers);//反转
 5         System.out.println(numbers);
 6         Collections.shuffle(numbers);//打乱顺序
 7         System.out.println(numbers);
 8         //最大值、最小值
 9         Collections.max(numbers);
10         Collections.min(numbers);
技术分享

  防止并发访问集合

1         java.util.List<String> list=Collections.synchronizedList(new ArrayList<String>());
2         Map<Integer, String> map=Collections.synchronizedMap(new HashMap<Integer,String>());

  只读集合

        java.util.List<String> words=Collections.unmodifiableList(new ArrayList<String>());

Java Collection

标签:

原文地址:http://www.cnblogs.com/1315925303zxz/p/5403216.html

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