Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TreeMap ,TreeSet with Comparator

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run a following Prgm on TreeMap and TreeSet with Comparator.



The compiler is flaging an error at <<<<<<< Not compling.However removing the argument com makes it compilable.

Other Inforamtion:
  • AgeComparator is a Comparator which compares Dogs based on their names.
  • The constructor of the Dog has first argument age and second argument name.
  • Dog implements Comparable.


  • What mistake I might be doing?Ranchers ,Please help.
    [ December 18, 2006: Message edited by: Sanjeev Kumar Singh ]
     
    Mark Uppeteer
    Ranch Hand
    Posts: 159
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Sanjeev Kumar Singh
    Your comparator compares Dogs, but it should compare Strings because String is the type of your key, and it is according to the key that the sorty will happen.

    regards,
    Mark
     
    Sanjeev Singh
    Ranch Hand
    Posts: 381
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks very much Mark,
    I was under the wrong impression that it is the value whose type is responsible for the sorting.
    I have made the changes and now it is running..

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic