- package com.review.demo;
- //自定义的Person类没挂上啊
- import java.util.HashSet;
- import java.util.Iterator;
- public class HashSetTest {
- public static void main(String[] args) {
- // 创建HashSet集合对象
- HashSet set = new HashSet();
- //向集合中添加Person对象
- set.add(new Person("马云",53));
- set.add(new Person("刘强东",43));
- set.add(new Person("李彦宏",40));
- set.add(new Person("马化腾",41));
- set.add(new Person("马化腾",41));
- //遍历
- for (Iterator it = set.iterator(); it.hasNext();) {
- Person p = (Person) it.next();
- //输出Person
- System.out.println(p);
- }
- }
- }
复制代码
|
|