关于如何应用 Collections.sort 方法按 itemData ArrayList 中每个 grocItem 对象的优先级对我的数组列表进行排序的任何想法?
public class GroceryProgram {
private final static int GROC_SIZE = 6;
private final List<ItemData> itemData = new ArrayList<ItemData>();
private void setUpList() {
Scanner keyboard = new Scanner(System.in);
for (int i = 0; i < GROC_SIZE; i++) {
System.out.print("\nEnter item name (" + i + ") : ");
String name = keyboard.next();
System.out.print("\nEnter the price of item (" + i + ") : ");
double cost = keyboard.nextDouble();
System.out.print("\nEnter Priority Number (" + i + ") : ");
int priority = keyboard.nextInt();
ItemData grocItem = new ItemData(name, cost, priority);
itemData.add(grocItem); // add grocery items to itemData ArrayList
Collections.sort(grocItem);
for (Int priority : priority) {
System.out.println(integer);