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
mystrings.stream() .filter(value -> !value.isBlank())
will become
mystring.stream() .filter(Predicate.not(String::isBlank)
Add if you add it as a static import import static java.util.function.Predicate.not; and you get
mystring.stream() .filter(not(String::isBlank)
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.