I have a class called Employee which has employeeName
and employeeId
as its member variables.I am creating new Employee objects and then adding it
you should compare string
not with ==, but with equals()
method, and also you should override your compareTo
method to compare with employeeName
not with employeeId
, if you want it in that way.
(Employee)emp).employeeName.equals(this.employeeName)
and
public int compareTo(Employee emp) {
return (this.employeeName-emp.employeeName);
}