package J20250722;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author WanJl
 * @version 1.0
 * @title TestArrayList
 * @description
 * @create 2025/7/22
 */
public class TestArrayList {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        Student s1=new Student(1,"张三66",25);
        Student s2=new Student(2,"张三67",25);
        Student s3=new Student(3,"张三68",25);
        Student s4=new Student(4,"张三69",25);
        Student s5=new Student(5,"张三50",25);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        //获取索引值为3的学生的姓名
        Student student = list.get(3);
        System.out.println(student.getName());
        //移除集合中索引值为4的学生
        Student student1 = list.remove(4);
        System.out.println("被移除的学生是："+student1);

        //iterator
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            Student next = it.next();
            System.out.println(next);
        }
        System.out.println("------------------------------");
        //foreach
        for(Student s: list){
            System.out.println(s);
        }
        //清空集合
        list.clear();

    }
}
