DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Wat is method compareTo? (http://www.daniweb.com/forums/thread49164.html)

zidane28 Jul 3rd, 2006 12:10 am
Wat is method compareTo?
 
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:

cscgal Jul 3rd, 2006 12:33 am
Re: Wat is method compareTo?
 
I assume that it does something like 'a' > 'b' and "apple" < "aardvark"

zidane28 Jul 3rd, 2006 12:54 am
Re: Wat is method compareTo?
 
Ok.....But then tat is one thing tat I really don understand...
Why it giv a positive whwn it comes to
 "cat" compareTo ("Cat")
?

DaSogo Jul 4th, 2006 1:40 am
Re: Wat is method compareTo?
 
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.

Phaelax Jul 7th, 2006 3:32 am
Re: Wat is method compareTo?
 
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.


All times are GMT -4. The time now is 8:58 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC