Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Line Separator in Java
Strings have no newlines. We can form them into two lines by concatenating a newline string. Use System lineSeparator to get a platform-dependent newline string.
The following is an example.
Example
public class Demo {
public static void main(String[] args) {
String str = "one" + System.lineSeparator() + "two";
System.out.println(str);
}
}
Output
one two
Let us see another example. On Linux based system, the program will work correctly.
Example
public class Demo {
public static void main(String[] args) {
String str = System.lineSeparator();
System.out.println((int) str.charAt(0));
}
}
Output
10
Advertisements