What is the system lineSeparator() in Java?
This static lineSeparator() function helps to return the line separator string. This string is system-dependent and returns the same value all the time.
Syntax
public static String lineSeparator()
Parameters
NA: This function does not take any argument value.
Return Value
-
In Windows-based systems, this function will return
\r\nor a positive integer. -
In UNIX-based systems, the
lineSeparator()method will return\nor a positive integer. -
NullPointerException: It will throw null pointer exception when the string is
null.
Example
The code below helps to understand the working of the lineSeparator() method. It will return a number when the string is not null which will be the line separator.
import java.io.*;import java.lang.*;import java.nio.channels.Channel;// Main classpublic class EdPresso{// main methodpublic static void main(String[] args)throws NullPointerException, IOException{ // calling lineSeparatir()String str = System.lineSeparator();for (char ch : str.toCharArray()) {System.out.println((int)ch);}}}