package cn.itcast;
import java.util.Iterator;
import java.util.LinkedHashSet;
/*
* LinkedHashSet
* 在HashSet集合的基础上,使迭代顺序可预测
*/
public class Demo6 {
public static void main(String[] args) {
LinkedHashSet lhs = new LinkedHashSet();
lhs.add(new Person("唐嫣",28));
lhs.add(new Person("baby",26));
lhs.add(new Person("杨幂",29));
lhs.add(new Person("柳岩",32));
Iterator iterator = lhs.iterator();
while (iterator.hasNext()) {
Person person = (Person) iterator.next();
System.out.println(person);
}
}
}
|
|