I have a Generic method smallestValueInArray(T[] array)
and this method gets an Array of any Type. This method looks like this:
public class Helper {
public static <T extends Comparable<T>> T smallestValueInArray(T[] array) {
T smallestValue = array[0];
T smallerTempValue = array[0];
for (int i = 0; i < array.length - 2; i+=2) {
if (array[i].compareTo(array[i+1]) < 0) {
smallerTempValue = array[i];
} else {
smallerTempValue = array[i+1];
}
if (smallestValue.compareTo(smallerTempValue) > 0) {
smallestValue = smallerTempValue;
}
}
return smallestValue;
}
}
In the Main method I want to do something like this:
for (int i = 0; i < stringArray.length; i++) {
someOtherArray[i] = Helper.smallestValueInArray(stringArray);
Helper.deleteElement(stringArray, stringArray[i]);
}
So I want to loop through stringArray
, find the smallest element in that Array and add that element to a new array someOtherArray
. After that I want to use a method deleteElement()
and this method gets two parameters, first one is an Array, and the seccond one is the element position in that Array which should be deleted.
How should my deleteElement()
method look like?
Important: I dont want to convert my array in a List and than use list.remove()!