|
@@ -1,5 +1,7 @@
|
1
|
1
|
package com.zipcodewilmington.arrayutility;
|
2
|
2
|
|
|
3
|
+import java.lang.reflect.Array;
|
|
4
|
+import java.util.ArrayList;
|
3
|
5
|
import java.util.Arrays;
|
4
|
6
|
import java.util.List;
|
5
|
7
|
|
|
@@ -48,7 +50,12 @@ public class ArrayUtility<E> {
|
48
|
50
|
}
|
49
|
51
|
|
50
|
52
|
public E[] removeValue(E valueToRemove) {
|
51
|
|
- while (Arrays.asList(elementArr).remove(valueToRemove)) {}
|
52
|
|
- return elementArr;
|
|
53
|
+ ArrayList<E> removedArrList = new ArrayList<>(Arrays.asList(elementArr));
|
|
54
|
+ while (removedArrList.remove(valueToRemove)) {}
|
|
55
|
+ E[] arr = (E[]) Array.newInstance(this.elementArr.getClass().getComponentType(), removedArrList.size());
|
|
56
|
+ for (int index = 0; index < removedArrList.size(); index++) {
|
|
57
|
+ arr[index] = removedArrList.get(index);
|
|
58
|
+ }
|
|
59
|
+ return arr;
|
53
|
60
|
}
|
54
|
61
|
}
|