Examples of Java 8

UPDATED: 27 September 2016
Java 8
Using IntStream over for loop in Java 8

How to iterate over stream and increment index value in Lambda Expression?
Many of you having trouble for increment index value inside Lambda expression because of Local variable index defined in an enclosing scope must be final or effectively final. There is an alternative for that...

How to get(collect) List of Properties (String, Double, Integer) from List of beans in Java 8?
This little excerpt shows How you can fetch List<String>, List<Double>, List<Integer>, List<Object>, etc... from List<Beans>. And it also explains the use of map method in stream.

How to convert List to Map in Java 8 using Stream API?
Code snippet demonstrate converting List<T> to Map<K,V>.

Example of Collectors minBy in Lambda expression
This static method from package java.util.stream and class Collectors used to find maximum value from given Collection. This method takes Comparator as an argument.

Example of Collectors maxBy in Lambda expression
This static method from package java.util.stream and class Collectors used to find maximum value from given Collection. This method takes Comparator as an argument.

Example of distinct in Java 8
Returns a stream consisting of the distinct elements (according to Object.equals(Object)) of this stream.

How flatMap works in Java 8 with Example
Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)



Example of mapToInt in Java 8
Returns an IntStream consisting of the results of applying the given function to the elements of this stream.

Example of mapToLong in Java 8
Returns a LongStream consisting of the results of applying the given function to the elements of this stream.

Example of mapToDouble in Java 8
Returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.

How to sum values from List, Set and Map using stream in Java 8?

0 comments :