Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取存储在数组列表的数组列表中的对象的属性?_Java_Arraylist_Anylogic - Fatal编程技术网

Java 如何获取存储在数组列表的数组列表中的对象的属性?

Java 如何获取存储在数组列表的数组列表中的对象的属性?,java,arraylist,anylogic,Java,Arraylist,Anylogic,我有一个arrayList LAL,它通过add函数填充了其他arrayList,如下所示: for(int i=0;i<v_amountComponentOptions;i++){ ArrayList AL=new ArrayList<CustomerOrder>(); LAL.add(AL); } 当我尝试按如下方式绘制数量时,我得到一个错误。它说没有数量价值 traceln(LAL.get(0).get(0).quantity); 然而,当我写作时 t

我有一个arrayList LAL,它通过add函数填充了其他arrayList,如下所示:

for(int i=0;i<v_amountComponentOptions;i++){
    ArrayList AL=new ArrayList<CustomerOrder>();
    LAL.add(AL);
}
当我尝试按如下方式绘制数量时,我得到一个错误。它说没有数量价值

traceln(LAL.get(0).get(0).quantity);
然而,当我写作时

traceln(LAL.get(0).get(0).quantity);
然后,输出为:

root( product = 1, quantity = 63 )
我的观点是,我需要得到数量值。谁能告诉我怎么做?
多谢各位

一种可能性是使用流并将所有数量值放入列表中。假设数量是
整数
,并且数量值是可访问的,您可以这样做

List<Integer> list = LAL.stream()
                 .flatMap(List::stream)
                 .map(a->a.quantity)
                 .collect(Collectors.toList());
List List=LAL.stream()
.flatMap(列表::流)
.图(a->a.数量)
.collect(Collectors.toList());
如果你有干将,这会更好

List<Integer> list = LAL.stream()
                 .flatMap(List::stream)
                 .map(CustomerOrder::getQuantity)
                 .collect(Collectors.toList());
List List=LAL.stream()
.flatMap(列表::流)
.map(CustomerOrder::getQuantity)
.collect(Collectors.toList());

两个行为不同的语句看起来相同。还有你的班级是什么样子的?你们有接球手和二传手吗?这些字段可以访问吗?发布您的CustomerOrder类。看起来数量要么不存在于CustomerOrder上,要么是私有的。
List<Integer> list = LAL.stream()
                 .flatMap(List::stream)
                 .map(CustomerOrder::getQuantity)
                 .collect(Collectors.toList());