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,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- [Solution] POI: Cannot get a NUMERIC value from a STRING cell - Java
- How To Change Mac Terminal Text Color - MacOS
- Get Current Local Date and Time using Java 8 DateTime API - Java
- Connect to 3270 host IBM Mainframe using Mac Terminal (c3270) - MacOS
- SharePoint List redirect user after submitting form NewForm.aspx - SharePoint
- How to change Ping TTL value on macOS - MacOS
- Mac Shortcut for Fullscreen mode for App Window - MacOS
- Get the total size and number of objects of a AWS S3 bucket and folders - AWS