How to sort a HashSet?

后端 未结 19 2400
耶瑟儿~
耶瑟儿~ 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:36

    This simple command did the trick for me:

    myHashSet.toList.sorted
    

    I used this within a print statement, so if you need to actually persist the ordering, you may need to use TreeSets or other structures proposed on this thread.

    0 讨论(0)
提交回复
热议问题