Treeset to order elements in descending order

前端 未结 5 2038
囚心锁ツ
囚心锁ツ 2020-12-09 15:25

Here is the piece of code that I have used for Java 5.0

TreeSet treeSetObj = new TreeSet( Collections.reverseOrder() ) ;
         


        
5条回答
  •  感情败类
    2020-12-09 15:51

    TreeSet treeSetObj = new TreeSet(new Comparator()
      {
      public int compare(Integer i1,Integer i2)
            {
            return i2.compareTo(i1);
            }
      });
    

    there is need to flip the result. But I guess this is just a micro-optimization... Do you really need this ?

提交回复
热议问题