How-to articles, tricks, and solutions about JAVA-8
How to convert a Java 8 Stream to an Array?
To convert a Java 8 Stream to an array, you can use the toArray() method of the Stream interface.
How to get milliseconds from LocalDateTime in Java 8
To get the milliseconds from a LocalDateTime object in Java 8, you can use the toInstant method and the toEpochMilli method.
How to sum a list of integers with java streams?
You can use the reduce() operation in the Java Streams API to sum the elements of a list of integers.
How to use a Java8 lambda to sort a stream in reverse order?
To use a Java 8 lambda to sort a stream in reverse order, you can use the sorted() method of the Stream interface and pass a lambda function that compares the elements in reverse order.
Java 8 Distinct by property
To get a list of distinct elements by a property in Java 8, you can use the distinct() method of the Stream interface and the map() method to extract the property from each element.
Java 8 Iterable.forEach() vs foreach loop
In Java 8, the Iterable.forEach() method is a default method that allows you to iterate over the elements of an Iterable (such as a List or Set) and perform a specific action on each element.
Java 8 Lambda function that throws exception?
In Java 8, you can use a lambda expression to create a functional interface that throws an exception.
Java 8 List<V> into Map<K, V>
To convert a List<V> into a Map<K, V> in Java 8, you can use the toMap() method of the Collectors class from the java.util.stream package.