I am new to java and am attempting to make a bubble sort work for a double. For some reason sorting is a real hangup for me. Below is the code, but it isn't doing anything. It doesn't error out, but it also doesn't sort. I feel like it is a stupid syntax mistake. My goal is to get the value of an item in my item file to sort descending.
public static ArrayList<Item> sortValue(ArrayList<Item> example)
{
for (int i = 0; i < example.size() - 1; i++ )
for (int j = 0; j < example.size() - 1 - i; j++)
if (example.get(j).getValue() == (example.get(j+1).getValue())) {
example.add(j+1, example.remove(j));
}
return example;
}
I call the method at the beginning of another method:
sortValue(example);
And still get the below result:
books 2.0 2.0 2 2
shoes 1.0 1.0 1 1
sword 10.0 10.0 10 10
Not pretty but basically the 10's should be at the top. Appreciate suggestions!