The fastest way to output very big data in stdout in Java

I want to print a lot of data in Stdout in the fastest way. One way is that I use StringBuilder and keep adding output to it and then print stringbuffer. But sometimes this fails when the data to be printed is larger than the maximum size and produces a limited memory error with limited probability. (e.g. online referees). Is there any other better and faster way to print data?

+4
source share
1 answer

You can try the following:

try {    
  BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
  //.....
  log.flush();
}

Although writing to a file directly will be more efficient

+1
source

All Articles