In this blog post, We are going to learn the six new methods added to String class in Java 11.
Java 11 Version added few more methods to the string class. This method helps the developer to simply the coding styles and improve performance
Returns the Stream of strings separated with a line break from multi-line strings Syntax
Stream lines = string.lines();
This method can be rewritten in the older version using the stream as below
String linesExample= string.lines()
Trim() method is not Unicode aware compliant
multilinesstring.lines().forEach(System.out::println); // returns String lines demo
This method removes Unicode whitespace character from a string. This has also the same behavior like trim() method.
System.out.println(" cloud".strip()); // prints "cloud"
System.out.println("hadoop ".strip()); // prints "hadoop"
System.out.println(" cloudhadoop ".strip()); // prints "cloudhadoop"
This method removes a leading whitespace character from String
This method removes a trailing whitespace character from String.
stringTrailing+stringLeading is equal to strip() method.
This method is used to check if the string is empty or only contains whitespace characters
return the number of times the string want to repeat. number of times can be configured as a parameter to this method