我是初学者,我不知道如何访问我已建立的arraylist以便能够返回每种产品的饮料数量(例如4个Cokes)
P.S。该产品是我的其他类的名称。
到目前为止,这是我的代码:
let c = &mut a as *mut [[u8; 4]; 3];
答案 0 :(得分:2)
我认为这可能会有所帮助。试试看你得到了什么。实现作为VendingMachine类的方法。
public int getProductCount(String pName) throws IllegalArgumentException {
int count = 0;
if (pName == null) {
throw new IllegalArgumentException();
}
for (Product item : this.vending) {
//Assuming the instance variable of your Product class is called name
//Also assuming name is private and you have a getter method in your Product class
if (item.getName().equalsIgnoreCase(pName)) {
count++;
}
}
return count;
}