arraylist的查询和删除
//arraylist的遍历和增加
import java.util.ArrayList;public class test38 {public static void main(String[] args){ArrayList aa1=new ArrayList();//当前对象个数System.out.println(aa1.size());test35 xs1=new test35("歌谣",3,4);test35 xs2=new test35("小白",3,4);test35 xs3=new test35("小红",3,4);test35 xs4=new test35("小狗",3,4);aa1.add(xs1);aa1.add(xs2);aa1.add(xs3);//aa1.remove(xs1);aa1.add(1,xs4);//学生4在位置1的下标添加System.out.println("大小为"+aa1.size());for(int i=0;i<aa1.size();i++){test35 tv=(test35)aa1.get(i);System.out.println(tv);System.out.println("第"+(i+1)+"个学生姓名为"+tv.getName());}}
}
运行结果