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:

Recommended Answers

All 4 Replies

I assume that it does something like 'a' > 'b' and "apple" < "aardvark"

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

"cat" compareTo ("Cat")

?

Member Avatar for DaSogo

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.