package tutorial58;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
class Person{
private int id;
private String name;
// hashCode() and equal() methods were auto added from source by eclipse
// necessary as set had duplicates without it
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
public Person(int id,String name){
this.id = id;
this.name = name;
}
// had to add this to Person class as print didn't have a toString() method to print it out
public String toString(){
return id + " " + name;
}
}
public class App {
public static void main(String[] args) {
Person p1 = new Person(0,"bob");
Person p2 = new Person(1,"sue");
Person p3 = new Person(2,"mike");
Person p4 = new Person(1,"sue");
Map