Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I post this in wrong forum
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have assigned null to s2 at line 15. It does not affect s1
 
Yogesh Gnanapraksam
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a similar question below

 
Campbell Ritchie
Sheriff
Posts: 48415
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course null is a different location.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic