import java.util.HashMap; import java.util.Map; public class MapExample { public static void main(String[] args) { Map<String, Integer> map = new HashMap<>(); map.put("John", 25); map.put("Alice", 30); map.put("Bob", 20); int johnAge = map.get("John"); System.out.println("John's age is " + johnAge); map.remove("Alice"); for (Map.Entry<String, Integer> entry : map.entrySet()) { String name = entry.getKey(); int age = entry.getValue(); System.out.println(name + " is " + age + " years old."); } } }


上一篇:
下一篇:
切换中文