I have created a Student class like this:
public class Student implements Comparable {
private String firstName;
private String lastN
Since you have compared only first name in compareTo method, you need
@Override
public int compareTo(Student student) {
int comp = this.firstName.compareTo(student.firstName);
if(comp==0) return this.lastName.compareTo(student.lastName);
return comp;
}
when compareTo returns 0, treeSet assumes that its duplicate.