O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

There are several simple but useful lambda expressions and method references often used in practice:

Function<String, Integer> strLength = String::length;System.out.println(strLength.apply("3"));Function<String, Integer> parseInt = Integer::parseInt;System.out.println(parseInt.apply("3"));Consumer<String> consumer = System.out::println;consumer.accept("Hello!");

If we run them, the results would be as follows:

Here are a few useful methods for working with arrays and lists:

Function<Integer, String[]> createArray = String[]::new;String[] arr = createArray.apply(3);System.out.println("Array length=" + arr.length);int i = 0; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required