This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String " Watch "String " New topic
Author

String

free hoo
Greenhorn

Joined: Oct 23, 2000
Posts: 4
please any one explain what a reference means .
when written
String str = new String();
str is a reference to a new object , but what does str contain.
what if i write
String str="abc";
now what str contains.
freehoo
Eric Edwards
Ranch Hand

Joined: Feb 12, 2000
Posts: 60
Originally posted by free hoo:
please any one explain what a reference means .
when written
String str = new String();
str is a reference to a new object , but what does str contain.
what if i write
String str="abc";
now what str contains.
freehoo

when written
String str = new String();
at this point str contains NULL--nothing.
String str="abc";
now what str contains.
at this point str contains "abc"
Paul Selby
Ranch Hand

Joined: Oct 20, 2000
Posts: 41
String str;
str is NULL
String str = new String()
str refers to a String, which is empty ""
str = "abc"
str refers to a String containing "abc"
You had asked "what a reference means", so I not sure what you mean by "contains". str is said to contain "abc", generally speaking. The nitpick would be that technically str is a reference variable and not an object, so it doesn't contain "abc" but refers to the object.
Allen Alchian
Ranch Hand

Joined: Oct 11, 2000
Posts: 83
I agree with Paul according to my understanding of strings. To get more specific, str will contain the memory address of where the string "abc" is found...that is what is meant by a reference.


Allen
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
there is a clear and simple explanation of references here:
http://www.javaranch.com/campfire/StoryCups.html
free hoo
Greenhorn

Joined: Oct 23, 2000
Posts: 4
hi everybody
thank you .
 
Don't get me started about those stupid light bulbs.
 
subject: String
 
Similar Threads
strings immutable
How many String Objects
question regarding strings
Once more about Array
About String