add toArray(int[])
This commit is contained in:
@@ -20,12 +20,13 @@ public final class IntList implements Serializable, Cloneable {
|
||||
// TODO support sublists
|
||||
// TODO add retainAll
|
||||
// TODO add removeAll
|
||||
// TODO add retainAll for sorted lists
|
||||
// TODO add removeAll for sorted lists
|
||||
// TODO add removeIf
|
||||
// TODO add removeRange
|
||||
// TODO add replace
|
||||
// TODO add lastIndexOf
|
||||
// TODO add indexOf
|
||||
// TODO add toArray(int[] a)
|
||||
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
||||
// TODO toString
|
||||
|
||||
@@ -152,6 +153,7 @@ public final class IntList implements Serializable, Cloneable {
|
||||
|
||||
ensureCapacity(values.length);
|
||||
|
||||
// TODO do not copy the array twice
|
||||
final int[] newData = new int[data.length];
|
||||
System.arraycopy(data, 0, newData, 0, pos);
|
||||
System.arraycopy(values, 0, newData, pos, values.length);
|
||||
@@ -282,6 +284,15 @@ public final class IntList implements Serializable, Cloneable {
|
||||
return get(0, index);
|
||||
}
|
||||
|
||||
public int[] toArray(final int[] input) {
|
||||
|
||||
if (input.length < index) {
|
||||
return toArray();
|
||||
}
|
||||
System.arraycopy(data, 0, input, 0, index);
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the list into ascending order.
|
||||
*/
|
||||
@@ -451,4 +462,5 @@ public final class IntList implements Serializable, Cloneable {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user