→ FlowerYen: try HashMap<String, Integer>05/18 16:06
看完HashMap<String,Integer>知道可以用key找對應value值,若套用到我的程式實在是
想不出怎用,可以大概說明一下嗎?謝謝(原本我是想每個人選取到的菜色都以String方
式丟進ArrayList,但怎樣在Arraylist分辨同菜色的數量就卡住了)
※ 編輯: apout (101.12.146.121), 05/19/2016 11:01:17
→ FlowerYen: if (foodMap.get("雞腿飯") != null { 05/19 12:44
→ FlowerYen: foodMap.get("雞腿飯") += 1; 05/19 12:45
→ FlowerYen: } else { 05/19 12:45
→ FlowerYen: foodMap.put("雞腿飯", 1); 05/19 12:46
→ FlowerYen: } 05/19 12:46
→ FlowerYen: 用arryList也可以,使用contains去判斷 然後自己存數量 05/19 12:47
→ FlowerYen: if (foodList.contains("雞腿飯")) { 05/19 12:48
→ FlowerYen: countOfXXX += 1; 05/19 12:49
→ FlowerYen: } else { 05/19 12:49
→ FlowerYen: foodList.add("雞腿飯"); 05/19 12:49
→ FlowerYen: countOfXXX = 1; 05/19 12:49
→ FlowerYen: } 05/19 12:50