Top "Java-8" questions

Use this tag for questions specific to Java 8 which is version 8 (internal number 1.8) of the Java platform, released on 18 March 2014.

Java 8 - Difference between Optional.flatMap and Optional.map

What's the difference between these two methods: Optional.flatMap() and Optional.map()? An example would be appreciated.

java java-8 optional
Reverse a comparator in Java 8

I have an ArrayList and want sort it in descending order. I use for it java.util.stream.Stream.sorted(…

java sorting java-8 comparator java-stream
Is it possible to cast a Stream in Java 8?

Is it possible to cast a stream in Java 8? Say I have a list of objects, I can do something …

java java-8 java-stream
Java 8 NullPointerException in Collectors.toMap

The Java 8 Collectors.toMap throws a NullPointerException if one of the values is 'null'. I don't understand this behaviour, maps …

java nullpointerexception java-8 java-stream collectors
Checking if a list is empty in java 8

I am new to Java8. I have implemented lists and filters. I have done a null check in my code. …

filter java-8 java-stream empty-list
Move to next item using Java 8 foreach loop in stream

I have a problem with the stream of Java 8 foreach attempting to move on next item in loop. I cannot …

java java-8
What is the difference between putIfAbsent and computeIfAbsent in Java 8 Map ?

Reading an interesting articles the guys claims that the difference between the two function are: Both functions aspire to add …

java java-8
Java8: sum values from specific field of the objects in a list

Suppose to have a class Obj class Obj{ int field; } and that you have a list of Obj instances, i.…

java filter java-8 java-stream
Using JavaFX in JRE 8, “Access restriction” error

When trying to use javafx related classes in my new java 8 project I get an access restriction error from eclipse. …

java eclipse javafx java-8
How to check if a Java 8 Stream is empty?

How can I check if a Stream is empty and throw an exception if it's not, as a non-terminal operation? …

java java-8 java-stream