Java 8 Lambda : Comparator example
In this example, we will show you how to use Java 8 Lambda expression to write a Comparator to sort a List. To compare the Developer objects using their age.…
Java 8 – Convert List to Map
Few Java 8 examples to show you how to convert a List of objects into a Map, and how to handle the duplicated keys.
Java 8 Streams filter examples
In this tutorial, we will show you few Java 8 examples to demonstrate the use of Streams filter(), collect(), findAny() and orElse()
Java 8 BiPredicate Examples
In Java 8, BiPredicate is a functional interface, which accepts two arguments and returns a boolean, basically this BiPredicate is same with the Predicate, instead, it takes 2 arguments for…
Java 8 Predicate Examples
In Java 8, Predicate is a functional interface, which accepts an argument and returns a boolean. Usually, it used to apply in a filter for a collection of objects.
Java 8 Consumer Examples
In Java 8, Consumer is a functional interface; it takes an argument and returns nothing. It can act as Higher Order Function, so we can accepts Consumer as an argument,…
Java 8 forEach examples
In Java 8, we can use the new forEach to loop or iterate a Map, List, Set, or Stream. Review the forEach method signature, it accepts a functional interface Consumer.…
Java – Add new line in String
Different operating system has a different new line or line separator string: UNIX, Linux or Mac OSX = \n, Windows = \r\n . We can also use the Java 1.7…
Java 7 try-with-resources example
Before Java 7, we can close a resource with finally. In Java 7, a new try-with-resources approach is introduced, it helps to close resources automatically.