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,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- PowerShell ISE Alternative for Mac - Powershell
- Convert Java Object to JSON using Jackson Library - Java
- Add Animated Scrolling to Html Page Title Script - JavaScript
- Calculate Area of Trapezoid - C-Program
- Android Studio setup was canceled - How to resume - Android-Studio
- How to Add Tab in Python - Python
- How to Turn Off Assistive Access on iOS 17 - iOS
- How to fix Microsoft Teams Error Code caa70004 - Teams