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,
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
More Posts:
- [Solved] Mic not working on iPhone 7 after iOS 14 upgrade - Apple
- Mac Auto Move Mouse Pointer Every X Seconds to Keep Screen Awake - MacOS
- How to Select All Text in Vim/Vi editor - vi
- Steps to Change the Default Admin Password in Jenkins - Linux
- Google Chrome Update failed (error: 12) - Chrome
- How to display Toast on Button Click : Android - Android
- How to Stop Screen Recording on Mac - MacOS
- How to upgrade pip/pip3 package installer for Python - PIP