File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes the print out is just beyond my expectation 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 "the print out is just beyond my expectation" Watch "the print out is just beyond my expectation" New topic
Author

the print out is just beyond my expectation

jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18
System.out.println("s1==s1.toLowerCase() "+s1==s1.toLowerCase() );
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
s1.toLowerCase() returns a string which is not the same as that of s1

Meaning the reference bits of s1 is different as compared to the reference bits of the string returned by toLowerCase function.

Hence when you say s1 == s1.toLowerCase() you are comparing the bits which are unequal.


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I think that this operator always returns false because it takes he literal String "s1==s1.toLowerCase() ", concatenates it with s1 to create a new object, then checks whether the newly created object is the same object as another newly created object which is taken from s1 but with all characters in lower case.

It never is.

I base this on + having a higher precedence than ==, so the statement is:

System.out.println( ( "s1==s1.toLowerCase() " + s1 ) == s1.toLowerCase() );


Mike Gershman
SCJP 1.4, SCWCD in process
jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18
mike , great job, you hit the point. thanks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
We've had that kinda problem before: never fails


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the print out is just beyond my expectation
 
Similar Threads
Find one char in a String ? ? ?
STring object Creation
java.lang
String code
String tricky question