实例
用hashset创建对象数组之后,输出后是哈希值。
class hashsettest {
public static void main(String[] args) {
// Create a HashSet
HashSet<APP> hset = new HashSet<APP>(4);
APP a = new APP();
for (int i = 0; i < 4; i++) {
Random r = new Random();
a.setAge(r.nextInt());
//add elements to HashSet
hset.add(a);
}
System.out.println("HashSet contains: "+ hset);
}
}
public class APP {
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}