I have a method which sorts the Array list by the Item Id. I am trying to print out the same after sorting, but my code doesn't seem to do anything. Not sure if the code is wrong or i am not knowing what to display after sorting. Should i create a new Arraylist to store the swapped and sorted values and then display that??
Please take a look at the code below:
Code:
---------------------------------------------------------------------------
public static void sortItemNum(ArrayList<Item> itm)
{
System.out.println("The records sorted by Item Number:");
for(int out=itm.size()-1; out>1; out--)
{// outer loop (backward)
for(int in=0; in<out; in++)
{// inner loop (forward)
if( itm.get(0).getItem().getId() > itm.get(1).getItem().getId() ) // out of order?
swap(itm.get(0).getItem().getId(), itm.get(1).getItem().getId()); // swap them
}
}
for(int k=0; k<itm.size(); k++)
{
System.out.println(insure.get(k));
}
}
private static void swap(int one, int two)
{
int temp = one;
one = two;
two = temp;
}