import java.util.*; public class StringAppendTest1 { public static void main(String[] args) throws Exception { int n = Integer.parseInt(args[0]); StringBuilder sb = new StringBuilder("a"); for(int i = 0; i < n; i++) sb.append("a"); String s = sb.toString(); System.out.println("length(s) = " + s.length()); } } /* Better: StringAppendTest1 10000 -> 0.139 seconds StringAppendTest1 100000 -> 0.154 seconds StringAppendTest1 1000000 -> 0.190 seconds */