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

Sign up
Appearance settings

Commit 29900f9

Browse files
Challenge 48.
String, StringBuffer, immutability.
1 parent 8d1397f commit 29900f9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package challenge41_50;
2+
3+
/**
4+
* StringBuffer threadSafe
5+
* StringBuilder not threadSafe
6+
* String are immutable, StringBuffer are not.
7+
*/
8+
public class Challenge_48 {
9+
10+
public static void main( String[] args ) {
11+
String s = "Height";
12+
StringBuffer stringBuffer = new StringBuffer("sword");
13+
testRefs(s,stringBuffer);
14+
System.out.println("s = " + s+" sb = " + stringBuffer);
15+
}
16+
17+
static void testRefs(String str, StringBuffer stringBuffer){
18+
str = str + stringBuffer.toString();
19+
stringBuffer.append(str);
20+
str=null;
21+
stringBuffer=null;
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /