|
@@ -1,7 +1,7 @@
|
1
|
1
|
package com.zipcodewilmington.arrayutility;
|
2
|
2
|
|
3
|
|
-import java.lang.reflect.Array;
|
4
|
3
|
import java.util.ArrayList;
|
|
4
|
+import java.util.Arrays;
|
5
|
5
|
import java.util.Collections;
|
6
|
6
|
|
7
|
7
|
/**
|
|
@@ -11,6 +11,7 @@ public class ArrayUtility<T> {
|
11
|
11
|
|
12
|
12
|
private T [] myArray;
|
13
|
13
|
private ArrayList<T> myArrayList;
|
|
14
|
+ T[] resultArray;
|
14
|
15
|
|
15
|
16
|
public ArrayUtility(T[] myArray) {
|
16
|
17
|
this.myArray = myArray;
|
|
@@ -41,8 +42,6 @@ public class ArrayUtility<T> {
|
41
|
42
|
}
|
42
|
43
|
}
|
43
|
44
|
|
44
|
|
-
|
45
|
|
-
|
46
|
45
|
return mostCommon;
|
47
|
46
|
}
|
48
|
47
|
|
|
@@ -57,7 +56,14 @@ public class ArrayUtility<T> {
|
57
|
56
|
}
|
58
|
57
|
|
59
|
58
|
public T[] removeValue(T valueToRemove){
|
60
|
|
- //gT[] resultArray = (T[])Array.newInstance(T[],0);
|
61
|
|
- return null;
|
|
59
|
+ int resultArrayIndex=0;
|
|
60
|
+ resultArray = Arrays.copyOf(myArray,myArray.length-getNumberOfOccurrences(valueToRemove));
|
|
61
|
+ for(int i=0;i<myArray.length;i++){
|
|
62
|
+ if(!myArray[i].equals(valueToRemove)){
|
|
63
|
+ resultArray[resultArrayIndex]=myArray[i];
|
|
64
|
+ resultArrayIndex++;
|
|
65
|
+ }
|
|
66
|
+ }
|
|
67
|
+ return resultArray;
|
62
|
68
|
}
|
63
|
69
|
}
|