在Java 11中,新的默认方法toArray(IntFunction)
已添加到java.util.Collection
接口,该接口允许将集合的元素传输到所需运行时类型的新创建的数组。
例如:
// Java 11
List<String> list = Arrays.asList("foo","bar","baz");
String[] array = list.toArray(String[]::new);
// The above is equivalent to:
String[] array2 = list.toArray(new String[0]);
翻译自: https://www.javacodegeeks.com/2019/01/java-11-converting-collection-array.html