aspose file tools*
The moose likes Beginning Java and the fly likes Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strings" Watch "Strings" New topic
Author

Strings

Sanapathi Madhuri
Greenhorn

Joined: Mar 02, 2002
Posts: 4
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

Joined: May 10, 2001
Posts: 3244
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.


Dave
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Sanapathi Madhuri
Greenhorn

Joined: Mar 02, 2002
Posts: 4
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

Joined: May 10, 2001
Posts: 3244
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

Joined: Mar 25, 2001
Posts: 1746
    
    2
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

Joined: Sep 29, 2000
Posts: 8521
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
 
subject: Strings