/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.stream.*;
class Person
{
private int id;
public Person
(String name,
int id
){ this.name = name;
this.id = id;
}
@Override
public boolean equals
(Object obj
) { if (obj == null) {
return false;
}
if (!Person.class.isAssignableFrom(obj.getClass())) {
return false;
}
final Person other = (Person) obj;
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
return false;
}
if (this.id != other.id) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 53 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 53 * hash + this.id;
return hash;
}
@Override
{
return "Name: " + name + " ID: " + id;
}
}
class Ideone
{
{
ArrayList<Person> persons = new ArrayList<>(); //add some elements
persons.add(new Person("test1",3));
persons.add(new Person("test1",4));
persons.add(new Person("test2",3));
persons.add(new Person("test1",3));
Set<Person> result = persons.stream().collect(Collectors.toSet());
result.
stream().
forEach(System.
out::println
); }
}