|
@@ -75,42 +75,9 @@ public class ArrayUtility<T> {
|
75
|
75
|
}
|
76
|
76
|
}
|
77
|
77
|
|
78
|
|
- T[] array = (T[]) list.toArray();
|
|
78
|
+ //T[] array = (T[]) list.toArray();
|
|
79
|
+ T[] array = (T[]) Array.newInstance(this.inputArray .getClass().getComponentType(), list.size());
|
79
|
80
|
System.out.println(" Array = " + array);
|
80
|
|
- return array;
|
|
81
|
+ return (T[]) list.toArray(array);
|
81
|
82
|
}
|
82
|
83
|
}
|
83
|
|
-/*
|
84
|
|
- */
|
85
|
|
-/*List<T>temp=new ArrayList<T>() ;
|
86
|
|
-
|
87
|
|
- for(int i=0;i<inputArray.length;i++){
|
88
|
|
-
|
89
|
|
- if(inputArray[i].equals(valueToRemove ) ){
|
90
|
|
- continue;
|
91
|
|
- }
|
92
|
|
- else
|
93
|
|
- temp.add(inputArray[i]);
|
94
|
|
-
|
95
|
|
- }
|
96
|
|
- T[] array = (T[]) Array.newInstance(inputArray.getClass().getComponentType(), temp.size());
|
97
|
|
- // T[] arr = (T[])Array.newInstance(this.temp.getClass().getComponentType(), temp.size());
|
98
|
|
- return list.toArray(array) ;
|
99
|
|
- }
|
100
|
|
-
|
101
|
|
-// public T[] removeValue(T valueToRemove) {
|
102
|
|
-// ArrayList<T> valuesNotRemoved = new ArrayList<>();
|
103
|
|
-//
|
104
|
|
-// for (T data:inputArray) {
|
105
|
|
-// if (!data.equals(valueToRemove)) {
|
106
|
|
-// valuesNotRemoved.add(data);
|
107
|
|
-// }
|
108
|
|
-// }
|
109
|
|
-// System.out.println(valueToRemove.getClass().getComponentType());
|
110
|
|
-// //was creating the new array but was empty.
|
111
|
|
-// T[] objs = (T[])Array.newInstance(valueToRemove.getClass().getComponentType(), valuesNotRemoved.size());
|
112
|
|
-//
|
113
|
|
-// return valuesNotRemoved.toArray(objs);
|
114
|
|
-// }
|
115
|
|
-
|
116
|
|
-*/
|