java console output code example
Example 1: how to print to console in java
System.out.println("Hello World!");
System.out.print("Hello World");
int a = 1;
System.out.println(a);
Example 2: How to print in console java
public class ConsoleTest {
public static void main(String[] args) {
System.out.println("Console is: " + System.console());
}
}
Example 3: how to print to the console in java
System.out.println("Text");
Example 4: capture console output java
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
System.out.println("Foofoofoo!");
System.out.flush();
System.setOut(old);
System.out.println("Here: " + baos.toString());