【发布时间】:2020-09-29 06:21:07
【问题描述】:
我有一个对象类型的数组列表的数组列表,试图获取特定数组列表的大小,但我一直在获取整个数组列表的大小
healthyKoalas = new ArrayList<Koala>();
hKoalas = new ArrayList<ArrayList<Koala>>();
public void hkoala(int x)
{
for (int i=0; i<x; i++) // x is the number of healthy koalas in an observation point
{
int age = (int)(Math.random()*18)+1;
Koala k = new Koala(age);
addHKoala(k);
healthyKoalas.sort(Comparator.comparing(Koala::getAge).reversed());
//Collections.sort(healthyKoalas, Collections.reverseOrder());
}
hKoalas.add(healthyKoalas);
}
然后当我尝试
hKoalas.get(x).size();
它给了我所有考拉对象的数量,而我想获得特定内部数组列表的大小
【问题讨论】:
-
public void hkoala(int x) { for (int i=0; i
-
this 回答你的问题了吗?
-
请提供更多信息,例如数组列表,以便我们更好地理解您的观点。
-
ArrayList
= new ArrayList (); hKoalas > = new ArrayList >(); -
public void hkoala(int x) { for (int i=0; i