groovy - (Groovy) 向 ArrayList 添加多个值
问题描述
正如标题所说,我想在 Groovy 中向我的 arrayList 添加多个值。但它不被接受。
Collection<String> actorCollection = new ArrayList<>();
actorCollection.add("first","second");
如果只有一个值,它就可以完美运行。
提前致谢!
解决方案
使用addAll
:actorCollection.addAll("first","second")
注意:Groovy 的列表文字将为您提供一个数组列表。所以可以从一开始就写def actorCollection = []
甚至... = ["first", "second"]
用值填充列表。
推荐阅读
- c++ - FObjectFinder 访问冲突
- python - Python - 替换exec中的函数和其中导入的模块
- c# - 模拟函数返回其输入时的 TargetParameterCountException
- azure - 删除 ARM 模板数据工厂中的某些组件?
- asp.net-core - 将字符串数组从控制器发送到 ASP.NET Core 服务器端渲染 JavaScript
- python - 更新 2.7 版的 python 代码,以在 3.0 版上运行
- python - 在python中读取多个Tweet JSON文件有困难(附上文件的链接)
- ios - 使用谷歌地图时出错,错误是 - libc++abi.dylib:以 NSException 类型的未捕获异常终止
- python - 从抓取到 CSV 文件
- c++ - 如何在模板成员中引用派生类?