collection存储遍历

public class Student {
private String name;
private int age;

public Student() {
}

public Student(String name, int age) {
this.name = name;
this.age = 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;
}

}




package com.czie.iot1913.lps01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
* @author 1944900433@qq.com
* @date 2022-03-17 13:21
*/
public class StudentDemo01 {
public static void main(String[] args) {
Collection<Student> c = new ArrayList<Student>();
Student s1 = new Student("刘品金", 41);
Student s2 = new Student("刘品木", 21);
Student s3 = new Student("刘品水", 31);
Student s4 = new Student("刘品火", 51);
Student s5 = new Student("刘品土", 61);
c.add(s1);
c.add(s2);
c.add(s3);
c.add(s4);
c.add(s5);
Iterator<Student> ite = c.iterator();
while (ite.hasNext()) {
Student s = ite.next();
System.out.println(s.getName() + "," + s.getAge());
}
}
}







posted @   刘品水  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示