23,405
社区成员
发帖
与我相关
我的任务
分享
static Map<String, Integer> map = new HashMap<String, Integer>();
static void add(String s) {
if (!map.containsKey(s))
map.put(s, 1);
else
map.put(s, map.get(s) + 1);
}
static void remove(String s) {
if (map.containsKey(s)) {
int count = map.get(s) - 1;
if (count != 0)
map.put(s, count);
else
map.remove(s);
} else
throw new UnsupportedOperationException("Sorry 商品不存在!");
}
static Map<String,Integer> map = new HashMap<String,Integer>();
static void add(String s) {
if(!map.containsKey(s))map.put(s,1);
else map.put(s,map.get(s)+1);
}
static void remove(String s) {
if(!map.containsKey(s))map.remove(s);
else throw new UnsupportedOperationException("Sorry 商品不存在!");
}