From ba51b62a53a0b7da8032122b14daca68f0ffb50a Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 3 Dec 2017 09:26:52 +0100 Subject: [PATCH] use Arrays.copy or Arrays.copyOfRange where applicable Arrays.copy is easier to use than System.arrayCopy. --- .../main/java/org/lucares/collections/IntList.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java index b6a3979..b9c99d1 100644 --- a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java +++ b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java @@ -80,8 +80,7 @@ public final class IntList implements Serializable, Cloneable { * if the specified {@link IntList} is null */ public IntList(final IntList intList) { - data = new int[intList.getCapacity()]; - System.arraycopy(intList.data, 0, data, 0, intList.size()); + data = Arrays.copyOf(intList.data, intList.size()); size = intList.size(); sorted = intList.sorted; } @@ -436,9 +435,7 @@ public final class IntList implements Serializable, Cloneable { if (from + length > size) { throw new IndexOutOfBoundsException("from: " + from + " length: " + length); } - final int[] result = new int[length]; - System.arraycopy(data, from, result, 0, length); - return result; + return Arrays.copyOfRange(data, from, from + length); } /** @@ -511,9 +508,7 @@ public final class IntList implements Serializable, Cloneable { if (size == 0) { data = EMPTY_ARRAY; } else { - final int[] newData = new int[size]; - System.arraycopy(data, 0, newData, 0, size); - data = newData; + data = Arrays.copyOf(data, size); } }