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,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- Java 8 foreach loop code examples - Java
- Calculate Volume of Cone - C-Program
- Android [SDK Manager] The system cannot find the path specified - Android-Studio
- Best free Decompiler for Java - Java
- Fail to connect to camera service Android java RuntimeException - Android
- Make Android TextView Clickable like Buttons - Android
- [Fix] Java - Exception in thread main java.lang.IllegalThreadStateException - Java
- Cannot load PowerApps form in SharePoint Online due to repeated authentication - SharePoint