End of line (EOL), newline, line feed, line break, or carriage return characters are called as control characters in a text/String, it tells that this is the end of the line and the next text should appears on a new line.
This control character is represented in multiple ways based on which Operating System the file was created (file system)
Windows: \r\n
macOS (or Mac OS X): \r
Unix: \n
In Java Programming, if you want to get the newline character, you should make use of the lineSeparator() method from the System class.
Example:/**
* Code2care.org Java Examples
*
* How to get New Line Character in Java
*
*/
public class JavaNewLineExample {
public static void main(String[] args) {
String myText = "This is my first line." + System.lineSeparator() + "This is my second line.";
System.out.println(myText);
}
}
Output:
This is my first line.
This is my second line.

More Posts related to Java,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- Quick way to install AWS CLI for macOS Terminal - AWS
- List of Eclipse versions and future releases (2022-06) - Eclipse
- How to find files taking up space on your Mac - MacOS
- Command to know the installed Debian version? - Linux
- Java Program to generate random string - Java
- Eclipse : This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in - Eclipse
- Notepad++ insert a blank line above or below the current line example - NotepadPlusPlus
- Fix zsh: permission denied: script.sh - zsh