This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Number of string objects being created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Number of string objects being created" Watch "Number of string objects being created" New topic
Author

Number of string objects being created

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629
Hi all,

In the following two cases, how many string objects are being created?



Thanks.
[ September 23, 2008: Message edited by: Arjun Reddy ]

Be Humble... Be Nice.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3867

1) 1 object
2) 2 objects (one in the String constant pool if there is no matching one for "hey" and one in the heap)


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629
Thanks Vijitha.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Number of string objects being created