HashMap和TreeMap
This commit is contained in:
@@ -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("李四存在");
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user