This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Strings" Watch "Strings" New topic
Author

Strings

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266



Output :

HelloequalsHellotrue
Hello==Hellotrue
Hello==Hellotrue
value of s1Hello
value of s2Hello
value of s1Hello
value of s2null // how ??? arent s1 and s2 pointing to the same location ?
Hello==nullfalse // how ???

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

sorry I post this in wrong forum


Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629


You have assigned null to s2 at line 15. It does not affect s1
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
Are you expecting a null pointer exception in this line ?
s1 == s2

It is other way of checking whether a string is null

if (s1==null) --> false

it works as expected....



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

jose chiramal wrote:value of s2null // how ??? arent s1 and s2 pointing to the same location ?

Well, not anymore. You let s2 point to a different location, to be precise no location at all.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
I have a similar question below

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Yes, of course null is a different location.
 
 
subject: Strings