This static lineSeparator()
function helps to return the line separator string. This string is system-dependent and returns the same value all the time.
public static String lineSeparator()
NA
: This function does not take any argument value.
In Windows-based systems, this function will return \r\n
or a positive integer.
In UNIX-based systems, the lineSeparator()
method will return \n
or a positive integer.
NullPointerException: It will throw null pointer exception when the string is null
.
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);}}}