Clear console screen in Java [duplicate]

As dirty hacks go, I like msparer’s solution. An even dirtier method that I’ve seen used (I would never do this myself. I swear. Really.) is to write a bunch of newlines to the console. This doesn’t clear the screen at all, but creates the illusion of a clear screen to the user.

char c="\n";
int length = 25;
char[] chars = new char[length];
Arrays.fill(chars, c);
System.out.print(String.valueOf(chars));

Leave a Comment