< prev index next >
src/java.base/share/classes/java/util/ArrayList.java
Print this page
rev 48215 : 8060192: Add default method <A> A[] Collection.toArray(IntFunction<A[]> generator)
Reviewed-by: martin, forax, psandoz
*** 24,33 ****
--- 24,34 ----
*/
package java.util;
import java.util.function.Consumer;
+ import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import jdk.internal.misc.SharedSecrets;
/**
*** 415,424 ****
--- 416,432 ----
if (a.length > size)
a[size] = null;
return a;
}
+ // no spec changes relative to supertype
+ public <T> T[] toArray(IntFunction<T[]> generator) {
+ T[] a = generator.apply(size);
+ System.arraycopy(elementData, 0, a, 0, size);
+ return a;
+ }
+
// Positional Access Operations
@SuppressWarnings("unchecked")
E elementData(int index) {
return (E) elementData[index];
< prev index next >