SE450: Taxonomy: A Builder in the Java APIs [59/63] |
java.lang.StringBuilder is a builder for java.lang.String.
+---------------------+ <<creates>> +---------------+ | StringBuilder |- - - - - - ->| <<immutable>> | +---------------------+ | String | | append(String):void | +---------------+ | toString():String | +---------------------+
Here is an example, showing the usage:
file:Main.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
package basics.stringbuffer; public class Main { private Main() {} static public void main (String[] args) { //stdlib.Trace.graphvizShowSteps (true); stdlib.Trace.run (); StringBuilder b = new StringBuilder(); b.append("I am "); b.append("a dog"); String s = b.toString(); System.out.println(s); b.append("matic jerk"); System.out.println(s); } }