• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

the print out is just beyond my expectation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println("s1==s1.toLowerCase() "+s1==s1.toLowerCase() );
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mike , great job, you hit the point. thanks
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We've had that kinda problem before: never fails
 
reply
    Bookmark Topic Watch Topic
  • New Topic