我需要向一个Java方法func(String, String...)
传递参数。
问题在于,我拥有的所有需要作为参数传递的字符串都存储在一个ArrayList
容器中。
例如:
for(...some condition...)
{
//the other method returns an ArrayList with different size in each iteration
ArrayList <String> values = someOtherMethod();
func(values) //values is an ArrayList<String>, containing all the arguments
}
我收到一个错误提示,指出无法将
ArrayList<String>
转换成 String
。
由于 someOtherMethod
方法在每次迭代时返回不同大小的容器,因此 values[0]、values[1] 等
不能作为参数传递。
我猜测 func
希望得到 X 个字符串变量,但我不知道如何将容器转换为 X 个变量,尤其当容器大小不固定时。
func
方法的精确签名是什么? - Sergey Kalinichenkofunc
方法的作用可能会减少猜测类型的回答,增加更高质量的回答。 - Simon Forsberg