• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings

 
sabah ammar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am not very sure how do strings perform in memory when == is tested with attributes.
please explain whatever u can . thanks
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String methods create a new, unique String only when they change the string they are called on.

"String".trim() does not change the string, so you get back a reference to "String" in the string literal pool.

All of your specific examples have this same effect.

== checks for the same object, so comparing two references to the same string in the string literal pool returns true
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic