Java IO Tutorial - Java PrintStream.print(String s)








Syntax

PrintStream.print(String s) has the following syntax.

public void print(String s)

Example

In the following code shows how to use PrintStream.print(String s) method.

/*from  ww w . j  a  va2  s .  c o m*/
import java.io.*;

public class Main {

   public static void main(String[] args) {
      String s = "from java2s.com";

      
      PrintStream ps = new PrintStream(System.out);

      // print string
      ps.print(s);
      ps.print(" This is an example");

      // flush the stream
      ps.flush();


   }
}

The code above generates the following result.