@@ -0,0 +1,1106 @@
+package grundkurs_java;%0A%0Apublic class Chap12 %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09StringOps.main(args);%0A%09%7D%0A%0A%7D%0A%0Aclass StringOps %7B%0A%0A%09static %7B%0A%09%09Runtime.getRuntime().addShutdownHook(new Thread() %7B%0A%09%09%09public void run() %7B%0A%09%09%09%09try %7B%0A%0A%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A%09public static void nobuffer(int iterations) %7B%0A%09%09final long startTime = System.currentTimeMillis();%0A%09%09String str = %22%22;%0A%09%09for (int i = 0; i %3C iterations; i++)%0A%09%09%09str = str + %22x%22;%0A%09%09System.out.println(%22nobuffer ran for %22%0A%09%09%09%09+ (System.currentTimeMillis() - startTime) + %22 seconds %22 + %22(%22%0A%09%09%09%09+ iterations + %22 iterations).%22);%0A%09%7D%0A%0A%09public static void buffer(int iterations) %7B%0A%09%09// Uses only 1 String-Buffer%0A%09%09final long startTime = System.currentTimeMillis();%0A%09%09StringBuffer buf = new StringBuffer(%22%22);%0A%09%09for (int i = 0; i %3C iterations; i++)%0A%09%09%09buf = buf.append(%22x%22);%0A%09%09System.out.println(%22buffer ran for %22%0A%09%09%09%09+ (System.currentTimeMillis() - startTime) + %22 seconds %22 + %22(%22%0A%09%09%09%09+ iterations + %22 iterations).%22);%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09nobuffer(10000);%0A%09%09buffer(10000);%0A%09%7D%0A%7D

"timing" string operations, chap12