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 Programmer Certification (SCJP/OCPJP) and the fly likes a question about 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question about string" Watch "a question about string" New topic
Author

a question about string

chang nanny
Greenhorn

Joined: Feb 15, 2004
Posts: 14
Hello,

Please look at the following code,

String x= new String("abc");

how objects are created?

Thanks.
Anuradha Shanmugam
Greenhorn

Joined: May 09, 2004
Posts: 8
Hi Chang,

Hope your question is not complete.

Anyway,

if your question is "how objects are created?" then the answer is when you use new keyword an instance to the String class is created in the heap.

if your question is "how many objects are created? " then the answer is 1

Regards,
Anu


Anuradha<br />(SCJP 1.4)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Anu check this out:
new String("abc") == "abc" returns false. So a new object is created which is different to the object "abc" residing in the string pool. So if this is the first time "abc" is used, then you could say two objects are created.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
 
subject: a question about string
 
Similar Threads
Tech Word Game
date format with MS Access database
ResultSet to Array
WA #1.....word association
How to convert byte array into string array?