Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java remove duplicates from list by property

import static java.util.Comparator.comparingInt;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;

...
List<Employee> unique = employee.stream()
                                .collect(collectingAndThen(toCollection(() -> new TreeSet<>(comparingInt(Employee::getId))),
                                                           ArrayList::new));
Comment

java remove duplicates from list by field

List<Obj> list = ...; // list contains multiple objects
Collection<Obj> nonDuplicateCollection = list.stream()
        .collect(Collectors.toMap(Obj::generateUniqueKey, Function.identity(), (a, b) -> a))
        .values();
Comment

PREVIOUS NEXT
Code Example
Java :: java else nothing 
Java :: println java 
Java :: conditions in for loop java 
Java :: how to declare array java 
Java :: sorting char array in java 
Java :: sort 2d array by column java 
Java :: iterating over a hashmap 
Java :: How to perform a breadth first search through a binary tree, in Java? 
Java :: do while loop in java 
Java :: java xmx example 
Java :: java date string 
Java :: java random unique key 
Java :: java filenotfoundexception 
Java :: intent filter 
Java :: Java List Sort Using sort() method 
Java :: change button text onclick java 
Java :: how to compare current date and time with another date and time in android 
Java :: valueof vs tostring 
Java :: java convert float to int 
Java :: jacoco code coverage 
Java :: How to close jframe on click of button 
Java :: java get year 
Java :: string to float java 
Java :: int to byte 
Java :: java set from string array 
Java :: java how to get all threads 
Java :: how to read file from console in java 
Java :: how to check if string is double or not in java 
Java :: check if sqlexception is duplicate entry java 
Java :: string length in java 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =