码迷,mamicode.com
首页 > 编程语言 > 详细

迭代器遍历数组

时间:2017-05-07 15:37:24      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:ring   style   color   oid   遍历数组   iter   hash   remove   遍历   

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);
    }

}

 

迭代器遍历数组

标签:ring   style   color   oid   遍历数组   iter   hash   remove   遍历   

原文地址:http://www.cnblogs.com/zyy1130/p/6820837.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!