import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class ShopProducts { public static void main(String[] args){ List pa = new ArrayList(); Collections.sort(pa, new ProductComparator()); } class ProductComparator implements Comparator{ public int compare(Object one, Object two){ return ((Product)one).getCategory().compareTo(((Product)two).getCategory()); } } } // Possible categories listed in the desirable order: // DVD, CD, GAME, BOOK, ACCESSORIES class Product{ private String name; private String category; private int id; public void setName(String name){ this.name = name; } public String getName(){ return name; } public void setCategory(String cat){ this.category = cat; } public String getCategory(){ return this.category; } public void setId(int id){ this.id = id; } }