HashMap和TreeMap

This commit is contained in:
2024-12-01 22:36:24 +08:00
parent 5a4df5e6f3
commit 4d9579e13d
3 changed files with 90 additions and 0 deletions

View File

@@ -1,4 +1,27 @@
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("李四存在");
// }
}
}