How do I get contains to recognize two objects w/ same data as equal?

I created an EmployeeId class that has an int field called myId. What methods and interfaces should I implement in EmployeeId so the output of the program below will be "Already Have That EmployeeId!" ? I have tried to implement the Comparable interface and the equals and hashCode methods but no luck. Thanks for the help!

Justin

EmployeeId emp1 =new EmployeeId(100);

EmployeeId emp2 =new EmployeeId(100);

Vector<EmployeeId> vec =new Vector<EmployeeId>();

vec.add(emp1);

if(vec.contains(emp2)){

System.out.println("Already Have That EmployeeId!");

}else{

System.out.println("Does Not Contain That EmployeeId!");

}

[1017 byte] By [jphilli9a] at [2007-11-26 17:42:27]
# 1
Return the employee ID from the hashCode() method, and return the equality of the two employee IDs from the equals(Object) method.
ejpa at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 2
That is exactly how I have implemented the equals and haschCode methods but the result is "Does Not Contain That EmployeeId!"
jphilli9a at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 3
better show us those methods
ejpa at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 4

public class EmployeeId implements Comparable<EmployeeId> {

int myId;

/** Creates a new instance of EmployeeId */

public EmployeeId(int id) {

myId = id;

}

public int compareTo(EmployeeId eid){

int result = 0;

if(myId != eid.myId){

result = myId > eid.myId ? 1:-1;

}

return result;

}

public boolean equals(EmployeeId eid){

return eid.myId == myId;

}

public int hashCode(){

return myId;

}

public int getId(){

return myId;

}

}

jphilli9a at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 5
Where's the override of Object.equals(Object)?You have another equals() method but who's going to call it?BTW compareTo can just return myId - emp.myId.
ejpa at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 6
Ok, that did it. So I wasn't actually overriding the equals method that is used by the Vector because the Vector class uses the equals method of the Object class which takes an Object as a parameter and my equals took an EmployeeId?
jphilli9a at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 7
Exactly. Vector is trying to call Object.equals(Object). It doesn't know anything about your class so how could it know about an equals method that takes an instance of your class as argument?
ejpa at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...
# 8
That makes sense, thanks for all the help!
jphilli9a at 2007-7-9 0:10:39 > top of Java-index,Core,Core APIs...