import java.util.HashMap;
public class StudentHashMapExample {
public static void main(String[] args) {
// 创建一个哈希映射
HashMap<String, Integer> studentMap = new HashMap<>();
// 添加学生信息到哈希映射
studentMap.put("Alice", 85);
studentMap.put("Bob", 92);
studentMap.put("Charlie", 78);
studentMap.put("David", 90);
// 获取学生信息
int aliceScore = studentMap.get("Alice");
System.out.println("Alice's score: " + aliceScore);
// 更新学生信息
studentMap.put("Alice", 88);
aliceScore = studentMap.get("Alice");
System.out.println("Updated Alice's score: " + aliceScore);
// 删除学生信息
studentMap.remove("Bob");
System.out.println("Bob's information removed.");
// 遍历学生信息
for (String name : studentMap.keySet()) {
int score = studentMap.get(name);
System.out.println(name + "'s score: " + score);
}
}
}