diff --git a/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java b/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java index a22874cc72fe216c09588c0b7b4dd1c4688c7ee3..c862a482b41b0c46619e4a6e9df77b031a845781 100644 --- a/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java +++ b/P/Sd1/Array/integerStoreUnbounded/src/main/java/de/hdm_stuttgart/mi/sd1/store/IntegerStore.java @@ -1,5 +1,7 @@ package de.hdm_stuttgart.mi.sd1.store; +import java.util.Arrays; + /** * A container holding a fixed * number of integer values. @@ -7,7 +9,7 @@ package de.hdm_stuttgart.mi.sd1.store; */ public class IntegerStore { - final static int defaultCapacity = 4; + final static int initialCapacity = 4; long[] values ; // Array containing our values int numValues = 0; // Number of values present in the container so far. @@ -17,7 +19,7 @@ public class IntegerStore { * */ public IntegerStore() { - values = new long[defaultCapacity]; + values = new long[initialCapacity]; } /** * Create a new store being able to @@ -56,11 +58,7 @@ public class IntegerStore { */ public void addValue(long value) { if (values.length <= numValues) { // Sufficient capacity available to add a new value? - final long[] currentArray = values; - values = new long[2 * currentArray.length]; // Double the current array's size. - for (int i = 0; i < currentArray.length; i++) { - values[i] = currentArray[i]; - } + values = Arrays.copyOf(values, 2 * values.length); // Double the current array's size. } values[numValues++] = value; }