TreeMap for key loss



  • Hello. Can't I understand if TreeMap can quarry the key off without using cycles and all that, for example, sending a comparator to it?

    My card:

    Map<Integer, Integer> returnMap = new TreeMap<Integer, Integer>()
    

    Sold:

    Map<Integer, Integer> returnMap = new TreeMap<Integer, Integer>(new Comparator<Integer>()
            {
                @Override
                public int compare(Integer o1, Integer o2)
                {
                    return o2 - o1;
                }
            });
    


  • Pass it. http://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html To the designer.

     Map<Integer, String> map = new TreeMap<Integer, String>(Collections.reverseOrder());
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2