Browsed by
Tag: Java 8

Terminal and Intermediate operations in the Java 8 Stream API

Terminal and Intermediate operations in the Java 8 Stream API

When working with the Stream API in Java 8, there are two groups of methods that you need to be aware of. These two groups are referred to as terminal and intermediate operators. Intermediate operators These are the methods in the Stream API that returns a new Stream, these are: distinct – Will only let through unique values, based on the objects equals method. filter – Takes a Predicate that should return true or false. True if the object should…

Read More Read More

Method References in Java 8

Method References in Java 8

Method references is a way to pass a reference to a method, that can be invoked at a later stage, with Lambdas. The criteria to a method reference, as with all Lambda expressions, is that it can be assigned to a functional interface. There are 4 different kinds of method references: Reference to a static method When the reference is a static method in a class, for example String::valueOf in the example below. Note, System.out returns an Object, so System.out::println…

Read More Read More

Lambdas in Java 8

Lambdas in Java 8

Java 8 has been out for a while now, and there are a lot of great posts about all the new features, but I’m preparing an introduction for a team that just started to use Java 8, so I thought I could just as well publish my notes as a blog post. Lambdas are actual “just” another way of creating anonymous inner classes, in the pre Java 8 world, we had to write: JButton jButton = new JButton(); jButton.addActionListener(new ActionListener()…

Read More Read More