我有一个重复值的地图:
("A", "1");
("B", "2");
("C", "2");
("D", "3");
("E", "3");
Run Code Online (Sandbox Code Playgroud)
我想要地图了
("A", "1");
("B", "2");
("D", "3");
Run Code Online (Sandbox Code Playgroud)
你知道如何摆脱重复的价值吗?
目前,我收到'java.util.ConcurrentModificationException'错误.
谢谢.
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("A", "1");
map.put("B", "2");
map.put("C", "2");
map.put("D", "3");
map.put("E", "3");
Set<String> keys = map.keySet(); // The set of keys in the map.
Iterator<String> keyIter = keys.iterator();
while (keyIter.hasNext()) {
String key = keyIter.next();
String value = map.get(key);
System.out.println(key + "\t" + value);
String nextValue = map.get(key); …Run Code Online (Sandbox Code Playgroud)