class User {
private String name;
public User( String name ) {
this.name = name;
}
public boolean equals( Object obj ) {
User user = (User) obj;
return user.name.equals( name );
}
public String toString() {
return name;
}
}
class Foo {
public static void main(String...arguments) { //1
User user1 = new User( "John" );
User user2 = new User( "Bill" );
User user3 = new User( "John" );
Set<User> userSet = new HashSet<User>();
userSet.add( user1 );
userSet.add( user2 );
userSet.add( user3 ); //2
System.out.println( "Count of users: " + userSet.size() ); //3
}
}
Login in to like
Login in to comment