// To sort items in a bag (which is only necessary when we want to // compare 2 bags), we need to be able to compare 2 items. We'll // assume it's just based on alphabetical order, so we'll use the // String class compareTo() method. import java.util.*; public class ItemComparator implements Comparator { public int compare(Object a, Object b) { String name1 = ((Item) a).toString(); String name2 = ((Item) b).toString(); return name1.compareTo(name2); } }