将字符串集合传递给(String ... values)

0 java string collections

我有一个非常简单的问题.

以下方法 -

newColumnsPredicate

将输入视为 String... colNames

以下是方法签名 -

public static SlicePredicate newColumnsPredicate(String... colNames) {

   //Some code

}
Run Code Online (Sandbox Code Playgroud)

我有以下方法collection of strings,我想在上述方法中使用 -

final Collection<String> attributeNames

所以我决定使用这样的东西 -

newColumnsPredicate(attributeNames.toString());

这是正确的方法吗?在我运行程序之后,我没有得到任何数据,所以我怀疑我添加的方式可能是错误的.

谁能帮我这个?

Gar*_*ryF 5

String ...是一个vararg参数.它用于指示参数应该是字符串数组,或者是您想要的多个String参数.

在集合上调用toString()只会返回一个字符串,该字符串组合了它包含的所有字符串.

您应该编写将您的集合转换为数组的内容,然后将其传入,例如:

attributeNames.toArray(new String[attributeNames.size ()])
Run Code Online (Sandbox Code Playgroud)