1

我有一套: Set<String> tmpSet = FastSet.newInstance();

当我关注这个问题时:如何将 Set 转换为 String[]?

我也这样做: String[] strArrStrings = includeFeatureIds.toArray(new String[0]);

我有这个例外:

Exception: java.lang.IllegalArgumentException
Message: Error running script at location [component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/KeywordSearch.groovy]: java.lang.UnsupportedOperationException: Destination array too small
---- cause ---------------------------------------------------------------------
Exception: java.lang.UnsupportedOperationException
Message: Destination array too small
---- stack trace ---------------------------------------------------------------
java.lang.UnsupportedOperationException: Destination array too small
javolution.util.FastCollection.toArray(FastCollection.java:351)

所以现在,我必须编码为:

for (FastSet.Record r = tmpSet.head(), end = tmpSet.tail(); (r = r.getNext()) != end;) {
         // copy one by one element to String[]  
     }

我的问题:无论如何(或实用程序)将 FastSet 转换为 String[]?

感谢 :-)

也可以看看:

4

1 回答 1

2

See FastCollection#toArray(T[])

Unlike standard Collection, this method does not try to resize the array

so you have to make the array the right size. Use

includeFeatureIds.toArray(new String[includeFeatureIds.size()])

instead of

includeFeatureIds.toArray(new String[0])
于 2013-10-07T03:23:17.337 回答