package HashMap;
import java.util.*;
//对这个HashMap进行反转,key变成value,value变成key
public class TestHashMap3 {
public static void main(String[] args) {
HashMap<String,String> dictionary=new HashMap<>();
HashMap<String,String> dictionary2=new HashMap<>();
dictionary.put("adc","物理英雄");
dictionary.put("apc", "魔法英雄");
dictionary.put("t", "坦克");
System.out.println("初始化后的dictionary:");
System.out.println(dictionary);
Set<String> keys = dictionary.keySet();
System.out.println("反转:");
for(String key : keys){
String value = dictionary.get(key);
dictionary2.put(value,key);
}
System.out.println(dictionary2);
}
}
JAVA-HashMap-键值反转
最新推荐文章于 2022-05-18 09:25:46 发布