![]() |
VOOZH | about |
In Java, print() and println() are methods of the PrintStream class used to display output on the console. Both methods print data such as strings, numbers, characters, and objects, but they differ in how they handle the cursor position after printing. Understanding their difference is important for formatting console output correctly.
print() method in Java is used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the end of the text at the console.
GfG1GfG2
println() method in Java is also used to display a text on the console. This text is passed as the parameter to this method in the form of String. This method prints the text on the console and the cursor remains at the start of the next line at the console.
GfG1 GfG2
Hello Java Welcome Developers
| Feature | print() | println() |
|---|---|---|
| Line Break | Does not add a new line | Adds a new line after printing |
| Cursor Position | Remains at end of current line | Moves to beginning of next line |
| Empty Call | Not allowed | Allowed (println()) |
| Output Format | Continuous output | Separate line output |
| Readability | Less readable for multiple outputs | More readable |
| Usage | Same-line printing | Line-by-line printing |
| Syntax | System.out.print(data); | System.out.println(data); |
| Newline Character | Not inserted | Automatically inserted |
| Common Use Case | Menus, formatted text, inline output | Messages, results, reports |
| Return Type | void | void |