A TreeSet or TreeMap that allow duplicates

前端 未结 7 1694
走了就别回头了
走了就别回头了 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-18 00:09

    Add the elements to the arraylist and then sort the elements using utility Collections.sort,. then implement comparable and write your own compareTo method according to your key.

    wont remove duplicates as well, can be sorted also:

    List<Integer> list = new ArrayList<>();
    
    Collections.sort(list,new Comparator<Integer>() 
    {
    
      @Override
    
    
      public int compare(Objectleft, Object right) {
    
    
    **your logic**
    
         return '';
    
      }
    
    }
    
    )
    ;
    
    0 讨论(0)
提交回复
热议问题