add toArray(int[])

This commit is contained in:
2017-10-07 10:01:38 +02:00
parent 56779368b8
commit cbe468cae8
2 changed files with 66 additions and 1 deletions

View File

@@ -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);
}
}
}