File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String object

 
reubin haz
Ranch Hand
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it true that:

1. String s1 = "abc";
2. String s2 = s1;
3. String s3 = "abc";

would create 1 object, and

4. String s1 = new String("abc");
5. String s2 = s1;
6. String s3 = new String("abc");

would create 3 object.

Please comment on this.
 
shetal bansal
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
R u sure on the no. of objects created in second case as I think the second case will produce 2 objects.
 
Steven Bell
Ranch Hand
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Assuming this next section is done in complete isolation of the previous section.


If the two sections of code are loaded by the same ClassLoader then the "abc" String literal will only be loaded once.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same type of questions are asked in this forum many times. Please do a search to get more idea.
[ June 23, 2005: Message edited by: Srinivasa Raghavan ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No! Not again!! Please spare us!
This forum is clogged with that question, how could you miss it?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this article from the forum bartender Corey. This might help you.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic