How to sort a HashSet?

后端 未结 19 2500
耶瑟儿~
耶瑟儿~ 2020-12-02 12:42

For lists, we use the Collections.sort(List) method. What if we want to sort a HashSet?

19条回答
  •  眼角桃花
    2020-12-02 13:34

    You can use Java 8 collectors and TreeSet

    list.stream().collect(Collectors.toCollection(TreeSet::new))

提交回复
热议问题