Set接口之HashSet

 1 package testBlog;
 2 
 3 import java.util.ArrayList;
 4 import java.util.Collection;
 5 import java.util.HashSet;
 6 import java.util.List;
 7 import java.util.Set;
 8 
 9 public class Test {
10     public static void main(String[] args) {
11         Set<Integer> all = new HashSet<Integer>();//HashSet存int型输出是有序的.这也是HashSet的特点
12         all.add(0);//小
13         all.add(2);//大
14         all.add(1);//中
15         System.out.println(all);
16         
17         Set<String> all1 = new HashSet<String>();//String的顺序比较奇怪
18         all1.add("abcde");//大
19         all1.add("abc");//小
20         all1.add("abcd");//中
21         System.out.println(all1);
22     }
23 }

结果:

[0, 1, 2]
[abc, abcde, abcd]

posted on 2018-01-04 17:34  三盛乙烯  阅读(139)  评论(0)    收藏  举报

导航