As far as I know 'bout method compareTo, it compare Strings......
It return 0 when if the strings are equal.
That one I know.....
It return negative number if the string that invokes method less than the strings that pass as an argument......
It return positive number if the string that invokes method greater than the strings that pass as an argument......
BUT wat is mean by "greater than" and "less than"?
If is value than is easy to understand...
But 4 string....
Can it compare like that?:eek:

11 Years
Discussion Span
Last Post by Phaelax

Ok.....But then tat is one thing tat I really don understand...
Why it giv a positive whwn it comes to

"cat" compareTo ("Cat")



look online for the ASCII character chart. It will give the character and its numerical ordering with in the chart. if a=1 and b=2, then a<b. If C=1 and c=2, then C<c. Lower case and upper case are different from one another.


compareTo() takes an object and compares it to the object that called it. For strings, it simply compares the characters. For other objects, it depends on the object. How the method is implemented determines what is necessary for another object to be considered equal to it. It returns 0 if the two are considered to be equal, or less than or greater than.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.