如何在java中将字符串集合转换为字符串数组

How to convert collection of strings to string array in java

本问题已经有最佳答案,请猛点这里访问。

我正试图把attributeNames,即collection of string,传递给接受string array的方法setColumnNames

1
2
3
4
5
6
7
8
9
10
11
12
13
public Map<String, String> getAttributes(String rowKey, Collection<String> attributeNames, String columnFamily) {

    try {

        SliceQuery<String, String, String> query = HFactory.createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get()).
                setKey(rowKey).setColumnFamily(columnFamily).setColumnNames(attributeNames);

    } catch (HectorException e) {
        LOG.error("Exception in CassandraHectorClient::getAttributes" +e+", RowKey =" +rowKey+", Attribute Names =" +attributeNames);
    }

    return null;
   }

setColumnNames的定义

1
SliceQuery<K, N, V> setColumnNames(N... columnNames);

每次我都有例外-

1
The method setColumnNames(String...) in the type SliceQuery<String,String,String> is not applicable for the arguments (Collection<String>)

如何将字符串的集合转换为Java中的字符串数组?有什么想法吗?


在javadocs collection from the:P></

T[] toArray(T[] a)

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

accepts that this method备注安阵列of the same type does not as the collection;容许你实例化Java在GENERIC阵列,虽然,我知道你会在它需要的工作。为更多的信息,看这问题。P></