I have an inventory class which creates an ArrayList full of objects Item, which is a class as well. I know that I have to call
Collections.sort(items);
in order to sort the ArrayList (it's called items by the way). The assignment says that I have to use an interface on the Item class, I don't know whether or not to implement Comparator or Comparable and then what to write for either the compareTo()
method or the compare()
method respectfully. Also I have the Collections.sort(items)
call right after I declare my ArrayList, is this okay?
Edit: My teacher just clarified that she wants us to implement Comparable<Item>
on the Item class.