*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Still not getting working of compareTo() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Still not getting working of compareTo() method" Watch "Still not getting working of compareTo() method" New topic
Author

Still not getting working of compareTo() method

saurabhthard aggarwal
Greenhorn

Joined: Nov 20, 2008
Posts: 22
/*WHEN COMPARETO () METHOD IS CALLED FOR ADDING THE SECOND ELEMENT IN THE TREESET WHICH OBJECT VALUE IS COMPARED TO WHICH OBJECT VALUE.
*/



Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

This code is very hard to understand. Please use the CODE tag when displaying code. Trying to post it normally strips the indentation and leads to character escape problems


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The code is unclear because of " words, so please use Code Tags [co de] [/co de]

saurabhthard aggarwal wrote:/* WHEN COMPARETO() IS CALLED FROM TREESET'S ADD() METHOD WHICH IS THE CALLING OBJECT AND WHICH IS THE CALLED OBJECT .
*/


ts1 - calling object
new Student() - called (passed) object


And as per your subject line, you asked about unable to understand compareTo(), Can you explain, What exactly you are unable to get ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
Your method should look like this....





or





It is likely that the implementation of compareTo() differs across data structures. Hope that helps!
 
Consider Paul's rocket mass heater.
 
subject: Still not getting working of compareTo() method