Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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
Stream 使用流打印ArrayList数据_Stream - Fatal编程技术网

Stream 使用流打印ArrayList数据

Stream 使用流打印ArrayList数据,stream,Stream,我使用下面的代码,但它不会逐行打印列表成员,而是打印整个列表。 ArrayList aList=新的ArrayList() 我得到的输出 [粉色、绿色、红色、黄色] 我需要在新行中打印这些元素。如下所示: aList.forEach(System.out::println); Stream.of(T…values)将数组作为参数,对于集合,可以直接在实例上调用forEach方法(如上所示)。得到了解决方案aList.Stream().parallel().forEach(s->System.o

我使用下面的代码,但它不会逐行打印列表成员,而是打印整个列表。 ArrayList aList=新的ArrayList()

我得到的输出 [粉色、绿色、红色、黄色]

我需要在新行中打印这些元素。

如下所示:

aList.forEach(System.out::println);

Stream.of(T…values)
将数组作为参数,对于集合,可以直接在实例上调用
forEach
方法(如上所示)。

得到了解决方案aList.Stream().parallel().forEach(s->System.out.println(s));
aList.forEach(System.out::println);