`
jackroomage
  • 浏览: 1195602 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

HashSet /LinkedHashSet/TreeSet排序的不同

 
阅读更多

HashSet set1 = new HashSet(Arrays.asList("b c e f g a".split(" ")));
        LinkedHashSet set2 = new LinkedHashSet(Arrays.asList("b c e f g a".split(" ")));
        SortedSet set3 = new TreeSet(Arrays.asList("b c e f g a".split(" ")));
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(set3);

 

输出结果为:

[f, g, e, b, c, a]
[b, c, e, f, g, a]
[a, b, c, e, f, g]

 

 

HashSet按Hash函数排序

LinkedHashSet按插入顺序排序

TreeSet按字母顺序排序

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics