Java System lineSeparator() Method
Example
Use the line separator to put text on two lines:
public class Main {
public static void main(String[] args) {
String text = "Hello" + System.lineSeparator() + "World";
System.out.println(text);
}
}
Definition and Usage
The lineSeparator() method returns the text that the operating system uses to end a line. On Linux and macOS it is "\n" (a new line character). On Windows it is "\r\n" (a carriage return and a new line character).
Use it when you write text, for example to a file, that should look right on the system where the program runs.
Syntax
public static String lineSeparator()
Parameter Values
None.
Technical Details
| Returns: | A String with the line separator of the system. |
|---|
Related Pages
❮ System Methods