package Set;
import java.util.Collections;
import java.util.HashSet;
public class HashSetDemo01 {
public static void main(String[] args) {
HashSet<dog> hashSet = new HashSet<>();
Collections.addAll(hashSet,new dog("乖乖",1),new dog("招财",3),new dog("招财",3));
System.out.println(hashSet);
![打印集合结果](https://img-blog.csdnimg.cn/209db4aa0ea1419b9f4f43fae96ecbd2.png#pic_center)
![dog类对equals和hashCode方法进行重写](https://img-blog.csdnimg.cn/fe43f68905894a228cd910e287925379.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYmFpMjU5MjU3,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
}
}
|