Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
24 lines (19 loc) · 803 Bytes

File metadata and controls

24 lines (19 loc) · 803 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
# StringBuilder
http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html
Mutable string. Implements `CharSequence` which is the main interface of String.
May be more efficient than `+` on String as it may avoid string object creation.
Smart compilers can optimize this out for simple `+`: http://stackoverflow.com/a/8595943/895245
but not necessarily inside loops: http://stackoverflow.com/a/30451908/895245
So just use it yourself.
*/
public class StringBufferCheat {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("ab");
sb.append("cd");
sb.append("ef");
assert sb.toString().equals("abcdef");
// ERROR: + does not work: the magic is just for String
//sb = sb + sb;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.