//arraylist的遍历和增加 import java . util . ArrayList ; public class test37 { public static void main ( String [] args ){ ArrayList aa1 = new ArrayList (); //当前对象个数 System . out . println ( aa1 . size ()); test35 xs1 = ne
//arraylist的遍历和增加
import java.util.ArrayList;
public class test37 {
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);
aa1.add(xs1);
aa1.add(xs2);
aa1.add(xs3);
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());
}
}
}