Sorting a LinkedHashSet

后端 未结 4 1694
旧巷少年郎
旧巷少年郎 2020-12-20 11:24

I\'m wondering if it\'s possible to sort a LinkedHashSet. I\'ve tried the statement

Collections.sort((List paragraph);

Howeve

4条回答
  •  北海茫月
    2020-12-20 11:51

    You can add LinkedHashSet object (linkedHashSet) to TreeSet and it will be sorted.

    TreeSet treeSet = new TreeSet();
    treeSet.addAll(linkedHashSet);
    

    treeSet is the sorted set.

    Note that you need to make these T type comparable(by implementing Comparator interface).

提交回复
热议问题