参考http://how2j.cn/k/collection/collection-sets/691.html#nowhere

HashSet LinkedHashSet TreeSet

HashSet: 无序
LinkedHashSet: 按照插入顺序
TreeSet: 从小到大排序

利用LinkedHashSet的既不重复,又有顺序的特性,把Math.PI中的数字,按照出现顺序打印出来,相同数字,只出现一次

LinkedHashSet linkedHashSet = new LinkedHashSet();
double pi = Math.PI;
for(char c: String.valueOf(pi).toCharArray()){
    if(c == '.')
        continue;
    linkedHashSet.add(c);
}
System.out.println(linkedHashSet);

 

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2021-08-26
  • 2022-01-28
  • 2021-11-29
  • 2021-08-08
  • 2021-07-27
猜你喜欢
  • 2021-05-21
  • 2021-12-03
  • 2021-10-28
  • 2021-11-30
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案