Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String references/values

 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm brain dead or something, because I got myself all confused over String. Which of the following is better, and why? I was about to do Case 3 when I started getting all loopy. This has been a long day, so forgive me! Oh, and if you happen to know where a reference is that explains your answer, I'd appreciate it!
Case 1

Case 2

Case 3

Case 4
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gerry,
You have two different outcomes here. In one scenario you set the member all to the empty string, and in the other scenario you set them to a string that you pass.
In either case you should probably never do something like:

All this does is create a spurious object. Since Strings are immutable, creating the new String instance gives you absolutely no advantage over:

hth,
bear
[ April 26, 2002: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic