# 其他 ###### tags: `Shannon` # 程式碼說明 1. EnumMap - EnumMap是為了讓你方便使用列舉型別Map物件 - EnumMap將根據列舉的順序來維護物件的排列順序 資源: https://openhome.cc/Gossip/JavaGossip-V2/EnumMap.htm 2. map.getOrDefault(key, default) * 如果map沒有這個key值,就回傳default ```typescript= public class FoodRepository { //EnumMap是為了讓你方便使用列舉型別Map物件 //EnumMap將根據列舉的順序來維護物件的排列順序 private Map<MealTime, List<FoodData>> foodDatabase = new EnumMap<>(MealTime.class); public List<FoodData> getFood(MealTime mealTime){ return foodDatabase.getOrDefault(mealTime, new ArrayList<>()); } public void addFood(MealTime mealTime, FoodData food){ foodDatabase.getOrDefault(mealTime, new ArrayList<>()).add(food); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up