This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes TreeMap ,TreeSet with Comparator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "TreeMap ,TreeSet with Comparator" Watch "TreeMap ,TreeSet with Comparator" New topic
Author

TreeMap ,TreeSet with Comparator

Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
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 ]

    ~Sanjeev Singh<br />SCJP 1.5
    Mark Uppeteer
    Ranch Hand

    Joined: Mar 02, 2004
    Posts: 159

    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


    I know where my towel is. (SCJP 5, OCPJWCD)
    [Free Quiz Tips for a fun night with friends or family] Flash games
    Sanjeev Singh
    Ranch Hand

    Joined: Nov 01, 2006
    Posts: 381
    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..

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: TreeMap ,TreeSet with Comparator