aspose file tools
The moose likes Beginning Java and the fly likes String references/values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String references/values" Watch "String references/values" New topic
Author

String references/values

Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
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


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)<br />Author of <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi" target="_blank" rel="nofollow">Posts in the Saloon</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56201
    
  13

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String references/values
 
Similar Threads
xslt transformation with DOMSource and Streamsource
JSTL, indirection of attributes
Nesting Enums within Enums
Problem inserting a single quote (')
Digester "aggressive mapping" Config Question