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.
public class Demo { public static void main(String[] args) { String str = "one" + System.lineSeparator() + "two"; System.out.println(str); } }
one two
Let us see another example. On Linux based system, the program will work correctly.
public class Demo { public static void main(String[] args) { String str = System.lineSeparator(); System.out.println((int) str.charAt(0)); } }
10