javacodegeeks.com

Java 8 Stream examples

This post will help you to understand some of the important and frequently used Stream operations in Java 8 which makes your programming with Java easy.Let’s take our traditional example, Employee and Department.public class Employee { private String name; private Integer age; private String city; private Department department; public Employee(String name, Integer age, String city, Department department) { this.name = name; this.age = age; this.city = city;

javacodegeeks.com

Java 8 map(), flatMap() examples

Using map () methodWhen programming, it is very common, processing data in order to collect some information from a collections of objects.Let’s say, we wanted find out the cities from all the employees in a particular company. Our employee class will be as follows.public class Employee { private String name; private Integer age; private String city; private String state; private Department department; public String getCity() { return city; } public

javacodegeeks.com

How to use filter() method in Java 8

Java 8 Stream interface introduces filter() method which can be used to filter out some elements from object collection based on a particular condition. This condition should be specified as a predicate which the filter() method accepts as an argument.The java.util.function.Predicate interface defines an abstract method named test() that accepts an object of generic type T and returns a boolean.Let’s do some coding

javacodegeeks.com

How many lines of code did you write to sort a collection of objects before Java 8 ?

How many lines of code did you write to sort a collection of objects before Java 8 ? How many, you will need with Java 8 ?You can do it with a single line in Java 8.Let’s see the following Employee class.public class Employee { private String name; private Integer age; public Employee(String name, Integer age) { super(); this.name = name; this.age = age; } public String getName() { return