System.lineSeparator() method in Java With Examples
The lineSeparator() is a built-in method in Java which returns the system-dependent line separator string. It always returns the same value – the initial value of the system property line.separator.
public static String lineSeparator()
Parameters: This method does not take any parameters.
Return Values: In any UNIX systems, it will return “\n” or a positive integer; and on Windows systems it returns “\r\n” or a positive integer.
Exception : It throws NullPointerException , if the string is null
Below programs illustrate the System.lineSeparator() method:
Program 1: To illustrate the working of static String lineSeparator() method.
Note: Here it returns 10. So here 10 is the line separator.
Program 2: To illustrate the working of static String lineSeparator() method for an integral value.
Note: Here it returns “\r\n” since its a Microsoft Windows systems.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.