HashMap에 containsKey 메소드에 키값을 넘겨주면 해당 키값이 HashMap에 있을경우 true를 없을 경우 false를 넘겨 줍니다.

HashMap에 containsValue 메소드에 값을 넘겨주면 해당 값이 HashMap에 있을경우 true를 없을 경우 false를 넘겨 줍니다.

아래는 키가 있는지 값이 있는지 출력해본 코드 입니다.

public static void main(String[] args) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("A", "aaa");
    map.put("B", "bbb");
    map.put("C", "ccc");
    
    System.out.println(map.containsKey("A"));
    System.out.println(map.containsKey("a"));
    System.out.println(map.containsValue("aaa"));
    System.out.println(map.containsValue("AAA"));
}

출력 결과는 아래와 같습니다.

true
false
true
false




같이 보면 괜찮을 것 같은 HashMap 사용법 강좌

http://forum.falinux.com/zbxe/?mid=lecture_tip&page=1&document_srl=570168

+ Recent posts