All posts tagged with 'Java8'

What’s the fuss with Java 8 Optional?

15-Apr-15

I’ve been asked several times lately by colleagues what the Optional<T> is good for, so today some more basic stuff. You can use the Optional class is as an elaborate null check like Optional<String> optionalString = Optional.ofNullable(someString); if(optionalString.isPresent()) { String string = optionalString.get(); }   // Or worse // String string = optionalString.orElse(null); // null […]

Read the complete article »

JaCoCo, Maven and NetBeans 8 integration

22-May-14

I was looking for a nice solution to measure the code coverage in my Spring Boot biking project. It should support Java 8, Maven and for added bonus, my IDE. I ended up using JaCoCo respectively the Maven plugin. If you expect a lengthier post, i must disappoint you. All that was need to turn […]

Read the complete article »

Java 8: Grouping stuff

06-May-14

I needed a function to sum (and therefor group) the values of a map of objects to Integers. My first solution was something like As you can see, i use the collect method with a custom supplier, accumulator and combiner. The supplier prepares a new map, the accumulator takes the map and an entry and […]

Read the complete article »

Java 8: Sort or find maximum, minimum entries in maps

05-May-14

This is cool: Map.Entry#comparingByKey and Map.Entry#comparingByValue. They both take another comparator or lambda that is used as a delegate for creating a Map.Entry comparator, that can be used to sort maps or find maximum and minimum pairs in a map by key or value like in the following example: import java.time.LocalDate; import java.util.Map; import java.util.Random; […]

Read the complete article »