运行 ❯
获取您自己的
Java 服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
import java.util.HashMap; public class Main { public static void main(String[] args) { HashMap<String, String> capitalCities = new HashMap<String, String>(); capitalCities.put("England", "London"); capitalCities.put("Germany", "Berlin"); capitalCities.put("Norway", "Oslo"); capitalCities.put("USA", "Washington DC"); capitalCities.merge("Canada", "Ottawa", (a, b) -> a + " -> " + b); capitalCities.merge("England", "London", (a, b) -> a + " -> " + b); capitalCities.merge("Germany", "Berlin", (a, b) -> a + " -> " + b); System.out.println(capitalCities); } }
{加拿大=渥太华, 美国=华盛顿特区, 挪威=奥斯陆, 英国=伦敦 -> 伦敦, 德国=柏林 -> 柏林}