Image Image Image Image Image Image Image Image Image Image

Mudassir Shahzad | November 16, 2018

Scroll to top

Top

No Comments

New JDK 11 features that I personally like and use

New JDK 11 features that I personally like and use
Mudassir Shahzad

Java Development Kit (JDK) 11 is now generally available bringing some productivity improvements and an HTTP Client API that implements HTTP/2.

You can download the new JDK from the oracle download center Java SE Development Kit 11

Following are some of the new features that I personally like and use:

 

The Not of a java.util.function.Predicate

So, this code

will become

Add if you add it as a static import import static java.util.function.Predicate.not; and you get

which is really simple and easy to read and makes your life easy.

 

java.util.Optional new method

  • boolean isEmpty(): If a value is not present, it returns true, otherwise it is false

This method is actually opposite of the already existing method boolean isPresent()

 

java.util.String new methods

  • boolean isBlank(): Returns true if the string is empty or contains only white space codepoints, otherwise false. You might as well go ahead and use <Optional> along with the new isEmpty() method. The choice is yours. You must be feeling like a King :)
  • String strip(): Returns a string whose value is this string, with all leading and trailing whitespace removed.
  • String stripLeading(): Returns a string whose value is this string, with all leading whitespace removed.
  • String stripTrainling(): Returns a string whose value is this string, with all trailing whitespace removed.

As astute developer like yourself must now be thinking about the trim() method. Why not use trim() ?
The answer, strip() is a “Unicode-aware” evolution of trim()

P.S. The relatively new unicode character \u2000 is above the character \u0020 ignored by the legacy trim() method as a whitespace.

Submit a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Object moved

Object moved to here.