Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings

 
Sanapathi Madhuri
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When two strings., say s1 and s2 are concatenated.. the result is an object . But what will be the reference of that object if we didnt assign any ?
Thx
Madhu.
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanapathi
Do you mean something like this:
System.out.println(s1 + s2);
In this case the concatenated Stings create a new String that is printed but there is no reference to it kept. They do not create a new literal that is stored in the String pool either, as far as know, somone a little more familiar with String and memory behavior might know better. As far as I know, only literals are kept in the pool.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A reference is created and passed to the System.out.println() method - once that method is done though, the reference is forgotten, and the String is eligible for GC.
 
Sanapathi Madhuri
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh...so there is any other way that i can refer to the concatenated strings ? (except an user defined string variable ?)
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanapathi
The only way to refer to something is to keep a reference to it.
The only way to keep a reference to something is to assign a variable to hold it.
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1796
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dave Vick:
The only way to refer to something is to keep a reference to it.
The only way to keep a reference to something is to assign a variable to hold it.

Well that's almost poetic, Dave!
For some fun reading along these same lines, take a look at the article on "references" in Roedy Green's Java Glossary.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh OH!!! I am laughing so hard I can hardly type < Cindy tried to catch her breath >
That was GREAT!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic