Sunday, October 5, 2025
HomeLanguagesJavaHow to Print Fast Output in Competitive Programming using Java?

How to Print Fast Output in Competitive Programming using Java?

In Competitive programming, most of the students use C++ as their primary language as it is faster than the other languages(e.g Java, Python) but for a student/professional who use Java as his/her primary language taking Input from input streams and printing fast output is the main difficulty faced during contests on competitive platforms(eg. CodeChef, CodeForces, Spoj, etc).

In this article, there defined the fastest method to print O/P using Java (Mainly in Competitive Programming).

BufferedWriter Class: It writes text to a character-output stream, buffering characters to provide for the efficient writing of single characters, arrays, and strings. It makes the performance fast.

BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));

Methods of BufferedWriter:

  • write(): writes a single character to the internal buffer of the writer.
  • write(char[] array): writes the characters from the specified array to the writer.
  • write(String data): writes the specified string to the writer.
  • flush(): used to clear the internal buffer.
  • close(): used to close the buffered writer.

Below is the implementation of the problem statement:

Java




// Print fast Output in Competitive Programming using JAVA
import java.io.*;
 
class GFG {
    public static void main(String[] args) throws Exception
    {
        String[] gfg = { "Geeks", "For", "Geeks" };
 
        BufferedWriter output = new BufferedWriter(
            new OutputStreamWriter(System.out));
 
        for (int i = 0; i < gfg.length; i++) {
            output.write(gfg[i] + "\n");
        }
 
        output.flush();
    }
}


Output

Geeks
For
Geeks

 

RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6706 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS