A TreeSet or TreeMap that allow duplicates

前端 未结 7 1697
走了就别回头了
走了就别回头了 2021-01-17 23:12

I need a Collection that sorts the element, but does not removes the duplicates.

I have gone for a TreeSet, since TreeSet actu

7条回答
  •  情话喂你
    2021-01-17 23:53

    you can sort a List using Collections.sort.

    given your Fund:

    List sortMe = new ArrayList(...);
    Collections.sort(sortMe, new Comparator() {
      @Override
      public int compare(Fund left, Fund right) {
        return left.fundValue.compareTo(right.fundValue);
      }
    });
    // sortMe is now sorted
    

提交回复
热议问题