How to clear the screen in Java?

To clear the console in Java, call System.out.print("\033[H\033[2J") followed by System.out.flush().

Printing these ANSI escape codes does the trick:

System.out.print("\033[H\033[2J");  
System.out.flush();