You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
5Why do I prefer StringBuilder to the plus notation?skiphoppy– skiphoppy2009-05-18 16:44:43 +00:00Commented May 18, 2009 at 16:44
-
10Efficiency, or rather an often-misguided attempt at it.Michael Myers– Michael Myers ♦2009-05-18 16:55:18 +00:00Commented May 18, 2009 at 16:55
-
2The attempt at efficiency is based, I think, on the fact that the Java compiler implements the string concatenation operator using StringBuilder (StringBuffer in pre-1.5 compilers). There is an old, but well-known article stating that there are performance benefits in certain situations to using StringBuffer (or StringBuilder, now). Here's the link: java.sun.com/developer/JDCTechTips/2002/tt0305.htmlPaul Morie– Paul Morie2009-05-18 17:32:18 +00:00Commented May 18, 2009 at 17:32
-
6Only when the compiler can't do it. For literals and constants, if you use a plus sign, the concatenation is done at compile-time. Using a StringBuilder forces it to happen at runtime, so it's not only more work, it's slower.johncip– johncip2011-05-09 07:30:35 +00:00Commented May 9, 2011 at 7:30
Add a comment
|
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-java