Kibret Tecle 6 gadus atpakaļ
vecāks
revīzija
a9fad0b314

+ 11
- 5
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Parādīt failu

1
 package com.zipcodewilmington.arrayutility;
1
 package com.zipcodewilmington.arrayutility;
2
 
2
 
3
-import java.lang.reflect.Array;
4
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
+import java.util.Arrays;
5
 import java.util.Collections;
5
 import java.util.Collections;
6
 
6
 
7
 /**
7
 /**
11
 
11
 
12
     private T [] myArray;
12
     private T [] myArray;
13
     private  ArrayList<T> myArrayList;
13
     private  ArrayList<T> myArrayList;
14
+    T[] resultArray;
14
 
15
 
15
     public ArrayUtility(T[] myArray) {
16
     public ArrayUtility(T[] myArray) {
16
         this.myArray = myArray;
17
         this.myArray = myArray;
41
             }
42
             }
42
         }
43
         }
43
 
44
 
44
-
45
-
46
         return mostCommon;
45
         return mostCommon;
47
     }
46
     }
48
 
47
 
57
     }
56
     }
58
 
57
 
59
     public T[] removeValue(T valueToRemove){
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
 }