I have a class below, and wanted to remove duplicate person which contain same name, how to do by using Java8 Lambda, expected List contains p1, p3 from the below.
Person:
public class Person {
public int id;
public String name;
public String city;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
Testing:
import java.util.ArrayList;
import java.util.List;
public class Testing {
public static void main(String[] args) {
List<Person> persons = new ArrayList<>();
Person p1 = new Person();
p1.setId(1);
p1.setName("Venkat");
p1.setCity("Bangalore");
Person p2 = new Person();
p2.setId(2);
p2.setName("Venkat");
p2.setCity("Bangalore");
Person p3 = new Person();
p3.setId(3);
p3.setName("Kumar");
p3.setCity("Chennai");
persons.add(p1);
persons.add(p2);
persons.add(p3);
}
}