Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created October 5, 2013 13:59
Show Gist options
  • Save flyfire/6841265 to your computer and use it in GitHub Desktop.
Save flyfire/6841265 to your computer and use it in GitHub Desktop.
import java.util.*;
class HashSetTest
{
public static void main(String[] args)
{
HashSet hs = new HashSet();
System.out.println(hs.add(new People("zhangshan")));
System.out.println(hs.add(new People("lishi")));
System.out.println(hs.add(new People("zhangshan")));
System.out.println(hs);
}
}
class People
{
String name;
public People(String name)
{
this.name = name;
}
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
else if (o instanceof People && o!=null)
{
op = (People)o;
if (this.name.equals(op.name))
{
return true;
}
}
returen false;
}
public String toString()
{
return this.name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment