Java2024/src/chapter6/Example14.java
2024-12-01 22:36:24 +08:00

28 lines
769 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chapter6;
import java.util.HashMap;
public class Example14 {
public static void main(String[] args) {
HashMap map = new HashMap(); // 创建Map对象
map.put("1","张三");//存储键和值
map.put("2","李四");
map.put("3","王五");
map.put("3", "赵六");
System.out.println("1" + map.get("1")); // 根据键获取值
System.out.println("2: " + map.get("2"));
System.out.println("3: " + map.get("3"));
System.out.println("键值对数量:" + map.size());
// if (map.containsKey("1")) {
// System.out.println("1号存在");
// }
//
// if (map.containsValue("李四")) {
// System.out.println("李四存在");
// }
}
}