Which is the fastest way to write to System.out
?
I know 3 ways so far:
1. the classic one:
for (int i = 0; i < 100000; i++) {
System.out.println( i );
}
2. Using StringBuilder
:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100000; i++) {
sb.append(i).append("\n");
}
System.out.print(sb.toString());
3. Wrapping System.out
in a Buffer like:
OutputStream out = new BufferedOutputStream(System.out);
for (int i = 0; i < 100000; i++) {
out.write((i + "\n").getBytes());
}
out.flush();
Is there any method that is more efficient than all of these?