I have 3 selection sort methods in my code that I pass an ArrayList of Integers, Doubles, and Strings too, but I was wondering if there was a way to alter my method to accept any type of ArrayList that I pass to it. Because if I try to change it to ArrayList Object then I cannot use a < or > comparison inside.
Here's what I have (which only works for ArrayLists of Integers):
private static ArrayList<Integer> selection_sort(ArrayList<Integer> arr) {
for (int i = 0; i < arr.size(); i++) {
int pos = i;
for (int j = i; j < arr.size(); j++) {
if (arr.get(j) < arr.get(pos))
pos = j;
}
int min = arr.get(pos);
arr.set(pos, arr.get(i));
arr.set(i, min);
}
return arr;
}