Java 11 – New String Methods

The commonly used String class received new API’s.  

What are the new API’s ? 

IsBlank()

Returns true if the string is empty or contains only white spaces, which is treated as blank.  

output

Lines()

Returns a stream of lines extracted from the string. 

output

Strip() 

Removes whites spaces from beginning & ending of string, as well as trailing and leading. Handles unicode unlike trim().

output

StripLeading() 

Removes leading whitespace.

output

StripTrailing() 

Removes trailing whitespace.

output

Repeat() 

Repeats the string n amount of times.

output

Code Example can be found here.

Final Thoughts 

This is meant to cut down on boilerplate code, as well as cut down on adding dependencies/imports for these functionalities. 

 

Leave a Reply

Your email address will not be published.