首页 > 解决方案 > (Groovy) 向 ArrayList 添加多个值

问题描述

正如标题所说,我想在 Groovy 中向我的 arrayList 添加多个值。但它不被接受。

Collection<String> actorCollection = new ArrayList<>();
actorCollection.add("first","second");

如果只有一个值,它就可以完美运行。

提前致谢!

标签: groovy

解决方案


使用addAllactorCollection.addAll("first","second")

注意:Groovy 的列表文字将为您提供一个数组列表。所以可以从一开始就写def actorCollection = []甚至... = ["first", "second"]用值填充列表。


推荐阅读