首页 > 其他 > 详细

1、向集合添加元素是否能成功。。。

时间:2016-01-23 10:24:55      阅读:137      评论:0      收藏:0      [点我收藏+]
 1 package com.hanqi;
 2 
 3 import java.util.ArrayList;
 4 import java.util.Collections;
 5 import java.util.HashSet;
 6 import java.util.List;
 7 import java.util.TreeSet;
 8 
 9 public class JKL {
10 
11         ArrayList<String> lis = new ArrayList<String>();
12         lis.add("A");
13         lis.add("a");
14         lis.add("c");
15         lis.add("C");
16         lis.add("a");
17         Collections.addAll(lis, "e", "f", "g", "h", "i");
18 
19         System.out.println("ArrayList输出 " + lis);
20 
21         HashSet<String> hs = new HashSet<String>();
22         
23         hs.add("A");
24         hs.add("a");
25         hs.add("c");
26         hs.add("C");
27         hs.add("a");
28 
29         Collections.addAll(hs, "e", "f", "g", "h", "i");
30 
31         System.out.println("HashSet输出 " + hs);
32 
33         TreeSet<String> ss = new TreeSet<String>();
34         
35         ss.add("A");
36         ss.add("a");
37         ss.add("c");
38         ss.add("C");
39         ss.add("a");
40         
41         Collections.addAll(ss, "e", "f", "g", "h", "i");// 可以重复,有序大写在前,小写在后,以顺序排列
42         
43         System.out.println("TreeSet输出 " + ss);
44 
45 }
46 }    

HashSet输出 [f, g, e, c, A, C, a, h, i]
TreeSet输出 [A, C, a, c, e, f, g, h, i]

1、向集合添加元素是否能成功。。。

原文:http://www.cnblogs.com/as1234as/p/5152815.html

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