gpt4 book ai didi

java - 关于数组列表中已定义的槽

转载 作者:行者123 更新时间:2023-12-02 06:26:40 36 4
gpt4 key购买 nike

我想知道是否可以预先填充数组列表的插槽?例如,可以通过这样的赋值操作来填充 st 数组:

    student [] st = new student[3];
st[0] = new student("214365879","eric banner", 67);
st[1] = new student("988634321","tony park",45);
st[2] = new student("009451223","paul summers",59);

但是使用 arraylist 来代替怎么可能呢?

最佳答案

It is possible to do by using add method from ArrayList

Person p1 = new Person("Izak","1234",33);
Person p2 = new Person("Igal","5668", 25);

List<Person> pList = new ArrayList<>();
pList.add(p1);
pList.add(p2);

关于java - 关于数组列表中已定义的槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20450146/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com