StringBuffer output = new StringBuffer(); for (1 .. 1000) { output.appends(get_long_string()); } System.out.print(output.toString());