企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ package a4; import java.util.ArrayList; public class Test { public static void main(String[] args) { ArrayList aa1= new ArrayList(); Xs xs1= new Xs("悟空",15,90); Xs xs2= new Xs("八戒",13,70); Xs xs3= new Xs("沙僧",14,80); Xs xs4= new Xs("小白龙",20,80); aa1.add(xs1); aa1.add(xs2); aa1.add(xs3); //System.out.println("大小为"+aa1.size()); //aa1.remove(1);//删除 //aa1.add(xs4);//继续添加 aa1.add(1,xs4);//插入到下标为1的位置,其他位置向下移动 for(int i=0;i<aa1.size();i++){ Xs tv =(Xs)aa1.get(i); System.out.println("第"+(i+1)+"个学生的姓名是"+tv.getXingming()); } } } class Xs{ private String xingming; private int xuehao; private int chengji; Xs(String xingming, int xuehao, int chengji) { this.xingming = xingming; this.xuehao = xuehao; this.chengji = chengji; } public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } public int getXuehao() { return xuehao; } public void setXuehao(int xuehao) { this.xuehao = xuehao; } public int getChengji() { return chengji; } public void setChengji(int chengji) { this.chengji = chengji; } } ~~~ ![](https://box.kancloud.cn/9378b282fc27fec1221445036b9fdd36_305x152.png)