package com.csdn;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @作者:Roc-xb
* @联系QQ:327844761
* @微信公众号:ewbang
* @若有帮助望采纳,谢谢!
*/
public class Student {
/**
* 姓名
*/
private String name;
/**
* 学号
*/
private String sno;
/**
* 成绩
*/
private double score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSno() {
return sno;
}
public void setSno(String sno) {
this.sno = sno;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public Student(String name, String sno, double score) {
super();
this.name = name;
this.sno = sno;
this.score = score;
}
@Override
public String toString() {
return "Student [name=" + name + ", sno=" + sno + ", score=" + score + "]";
}
public static void main(String[] args) {
List<Student> students = new ArrayList<>();
// 向集合中添加3名学生
students.add(new Student("张三", "101", 99));
students.add(new Student("李四", "102", 59));
students.add(new Student("王五", "103", 88));
// 在第二个学生前面新增2名学生
students.add(1, new Student("张三1", "104", 91));
students.add(2, new Student("张三2", "105", 92));
// 删除最后一名学生的信息
students.remove(students.size() - 1);
// 使用Iterator打印输出所有学生信息
Iterator<Student> iterator = students.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}