W3docs

How to clear the console?

To clear the console in most command-line interfaces (CLI), you can use the clear or cls command.

To clear the console in most command-line interfaces (CLI), you can use the clear or cls command.

Here's an example of how you can clear the console in a Unix-like CLI:

clear

Here's an example of how you can clear the console in a Windows CLI:

cls

Note that the clear or cls command only works in the OS-level terminal, and it will not work in a terminal window within an integrated development environment (IDE) such as Eclipse or IntelliJ. To clear the console from within a Java application, you can use ANSI escape codes:

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

Alternatively, you can use a third-party library like JLine or rely on IDE-specific keyboard shortcuts.