You can use the following function to clear the command line console:
For Windows:
public static void clrscr(){
//Clears Screen in java
try {
if (System.getProperty("os.name").contains("Windows"))
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
else
Runtime.getRuntime().exec("clear"); } catch (IOException | InterruptedException ex) {}
}
For Linux:
System.out.print("\033\143");