【发布时间】:2016-11-28 13:05:56
【问题描述】:
我有一个 Singleton 类,里面有一个 HashMap。 HashMap 由String 和Set<String> 组成:
private Map<String, Set<String>> mMap = new HashMap<>();
我想达到什么目标?
从Map 内的所有Set 值中删除给定项目。例如:
mMap.put(keyName, new HashSet<String>())
....
mViewsSwipeStates.get(keyName).add("1");
mViewsSwipeStates.get(keyName).add("2");
mViewsSwipeStates.get(keyName).add("3");
....
//Remove an item from the set
mMap.values().remove("3"); //Does not work
从Set 中删除项目的正确方法是什么?
【问题讨论】:
-
需要先从地图中获取物品:mViewsSwipeStates.get(keyName).remove(productCode);