叠代器遍歷數組
阿新 • • 發佈:2017-05-07
println 叠代 iterator ring import port super() out rri
public class Student { String name; int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Student(String name, int age) { super(); this.name = name; this.age = age; } @Override public String toString() { return "Student [name=" + name + ", age=" + age + "]"; } }
import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class StudentTest { public static void main(String[] args) { Set<Student>set=new HashSet<Student>(); set.add(new Student("a", 100)); set.add(new Student("b", 90)); set.add(new Student("c", 80)); set.add(new Student("d", 65)); set.add(new Student("e", 55)); Iterator<Student>ite=set.iterator(); while(ite.hasNext()){ Student s=ite.next(); if(s.age<60){ ite.remove(); } } System.out.println(set); } }
叠代器遍歷數組