Comparator example Java 8 Lambda expression

We’ll show you how to write a Comparator to sort a List using Java 8 Lambda expressions in this example. Classic Comparator example Lambda expression equivalent. Sort without Lambda A comparison of Developer objects based on their age is an example. Normally, you use Collections.sort and pass an anonymous Comparator class like this : Output […]

En Lire Plus

How to convert List to int[] in Java ?

List<Integer> to int[] To convert List<Integer> to int[] in java we can use les Streams, With Java 8, int[] can be converted to Integer[] easily : Integer[] is generally not a good map key, as others have said. However, we now have a reasonably clean and native code in terms of conversion. Also read , […]

En Lire Plus

forEach Java 8 Examples

To loop or iterate a Map, List, Set, or Stream in Java 8, we can use the new forEach method. Loop a Map 1,1 A standard method for looping a Map is shown below. 1.2 We can use forEach in Java 8 to loop through a Map and print out its entries. Output 1.3 The […]

En Lire Plus

Consumer Java 8 Examples, how to use ?

In Java 8, Consumer is a functional interface, it takes an argument and returns nothing. An interface with just one abstract method is referred to as a functional interface. They are limited to displaying only one type of feature. Lambda expressions can be used to describe a functional interface instance starting with Java 8. Some examples of […]

En Lire Plus

(SOLVED) How to find duplicate elements in a Stream (Java 8) ?

In Java 8 Stream, filter with Set.Add() is the fastest algorithm to find duplicate elements, because it loops only one time. The Collections.frequency is the slowest because it compares each item with a list – Collections.frequency(list, i). If we increase the size of the list, the performance will get slower.

En Lire Plus

(Solution) How to initialize a HashMap in Java ?

The result of an initialized HashMap is a mutable map or an immutable map: Mutable map : in this case we can modify the Map entries. Immutable map : in this case we can’t add or modify the Map entries, and if we modify it, it throws UnsupportedOperationException. To initialize a HashMap , there are […]

En Lire Plus

Lambda Expressions in JAVA 8 (Simple Tutorial)

Lambda Expression: Definition Before reading this tutorial try to Understand Java 8 Functional interfaces in 5 min Lambdas expression is considered the biggest novelty in Java 8, it is a form of method, more compact than a standard method, for which the name is implicit and the parameters can be omitted, as well as their […]

En Lire Plus

Understand Java 8 Functional (Simple Tutorial)

A functional interface is an interface with a single abstract method. The goal is to define the signature of a method that can be used to pass as a parameter : A reference to a static method A reference to an instance method A reference to a manufacturer A lambda expression. A functional interface can […]

En Lire Plus

Writing Nashorn Command-Line Scripts with Nake

Nake is a simplified version of Make (Cake, Jake, Rake) for Java 8 based on the Nashorn Javascript Engine. I wrote Nake to automate common tasks in our daily project business here at Pondus. You define tasks in a project-specific Nakefile and call those tasks from the command line. Tasks are written in Javascript empowered […]

En Lire Plus

Java : multi-line string, text blocks

Java multi-line string text blocks : This article will show you a few ways to declare and use a multi-line string in Java. String + String + String StringBuilder String.format StringWriter String.join (Java 8) Files.lines (Java 8) (“””) Java 13 and Java 14 text blocks (preview feature) Java multi-line string text blocks : Review an […]

En Lire Plus

(SOLVED) Cannot make a static reference to the non-static method

if you have this error that mean you are using your Repository interface in the place of you using and instance of it ,Exemple : if you have an interface PersonnelRepository and you want to use the function getOne(). if you do like that PersonnelRepository.getOne(id) you will have the error Cannot make a static reference […]

En Lire Plus

Patterns optionels

Patterns optionels : De nombreuses choses ont été introduites en Java 8 qui changent la façon de concevoir les applications et les API. Les lambdas bien sûr, l’API Stream également. Si tu es un habitué de ce blog, cher et précieux lecteur, tu es déjà au courant. Patterns optionels : Un autre élément a été […]

En Lire Plus