This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the print out is just beyond my expectation

 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("s1==s1.toLowerCase() "+s1==s1.toLowerCase() );
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() );
 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike , great job, you hit the point. thanks
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've had that kinda problem before: never fails
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic