String Object. Clarification needed
Posted
by mac
on Stack Overflow
See other posts from Stack Overflow
or by mac
Published on 2010-06-15T12:59:17Z
Indexed on
2010/06/15
13:02 UTC
Read the original article
Hit count: 169
Guys, help me clarify. Say i have the following line in my program:
jobSetupErrors.append("abc");
In the case above where jobSetupErrors is a StringBuilder(), what i see happen is:
- New String Object is created and assigned value "abc"
- value of that String object is assigned to the existing StringBuilder object
If that is correct, and I add 1 more line ...
jobSetupErrors.append("abc");
logger.info("abc");
In the above example are we creating String object separately 2 times?
If so, would it be more proper to do something like this?
String a = "abc";
jobSetupErrors.append(a);
logger.info(a);
Is this a better approach? Please advise
© Stack Overflow or respective owner