public class ImmutableStrings
1: //: appendixa:ImmutableStrings.java
2: // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
3: // www.BruceEckel.com. See copyright notice in CopyRight.txt.
4: // Demonstrating StringBuffer.
6: public class ImmutableStrings {
7: public static void main(String[] args) {
8: String foo = "foo";
9: String s = "abc" + foo +
10: "def" + Integer.toString(47);
11: System.out.println(s);
12: // The "equivalent" using StringBuffer:
13: StringBuffer sb =
14: new StringBuffer("abc"); // Creates String!
15: sb.append(foo);
16: sb.append("def"); // Creates String!
17: sb.append(Integer.toString(47));
18: System.out.println(sb);
19: }
20: } ///:~