package CHAPTER09;

import java.util.HashMap;

public class C9_11_HashMap {
    public static void main(String[] args) {
        // HashMap 생성 (학생 이름을 키로, 점수를 값으로 저장)
        HashMap<String, Integer> studentScores = new HashMap<>();

        // 데이터 추가
        studentScores.put("Alice", 85);
        studentScores.put("Bob", 92);
        studentScores.put("Charlie", 78);
        studentScores.put("Alice", 90); // 동일 키로 값 갱신

        // 모든 데이터 출력
        System.out.println("학생 성적 목록: " + studentScores);

        // 특정 키의 값 가져오기
        int score = studentScores.get("Bob");
        System.out.println("Bob의 점수: " + score);

        // 특정 키가 존재하는지 확인
        boolean hasCharlie = studentScores.containsKey("Charlie");
        System.out.println("Charlie 존재 여부: " + hasCharlie);

        // 특정 값이 존재하는지 확인
        boolean hasScore85 = studentScores.containsValue(85);
        System.out.println("점수 85 존재 여부: " + hasScore85);

        // 데이터 제거
        studentScores.remove("Charlie");
        System.out.println("Charlie 제거 후 목록: " + studentScores);

        // HashMap 크기 확인
        System.out.println("HashMap 크기: " + studentScores.size());

        // 모든 키와 값을 반복 출력
        System.out.println("학생별 성적:");
        for (String student : studentScores.keySet()) {
            System.out.println(student + ": " + studentScores.get(student));
        }

        // HashMap 비우기
        studentScores.clear();
        System.out.println("HashMap 비운 후: " + studentScores);
    }
}

