is collections.sort method only used for List type of collections?

前端 未结 7 535
予麋鹿
予麋鹿 2021-01-06 03:37

friends, I am new to Java-Collection. I want to ask does Collections.sort() method only used for/by collections which are List type. I was unable t

相关标签:
7条回答
  • 2021-01-06 04:07

    Yes, the Collections.sort methods are only for lists.

    You can't sort HashSet, but a TreeSet is automatically sorted as you add items, and LinkedHashSet is sorted by insertion order.

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