The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compareTo Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "compareTo" Watch "compareTo" New topic
Author

compareTo

Ahmad Mudassir
Greenhorn

Joined: Oct 16, 2000
Posts: 10
Hi,
could any one tell about the following code.
String s5 = "AMIT";
String s6 = "amit";
System.out.println(s5.compareTo(s6));
System.out.println(s6.compareTo(s5));
System.out.println(s6.compareTo(s6));
it would print
-32
32
0
how we calculate -32 and 32
bindu john
Greenhorn

Joined: Oct 04, 2000
Posts: 15
Hi
In the first case "AMIT" is compared with "amit".In the ASCII table 'A' got a value 65[decimal] and 'a' got value 97.
return type of compareTo is int which is 65-97 ie -32.
reverse is the case for second case
Bindu
[This message has been edited by bindu john (edited October 17, 2000).]
 
 
subject: compareTo
 
Threads others viewed
String comparison
s.compareTo()
strings doubt
Strings
urgent
IntelliJ Java IDE