Core Java

[Core Java] Map or List에 값이 포함되어 있는지 확인

헤르메스의날개 2012. 7. 3. 10:48
728x90

public static void main(String[] args) {
 
    Map<string> map = new HashMap<string>();
    map.put("A", "aaa");
    map.put("B", "bbb");
    map.put("C", "ccc");
    map.put("D", "ddd");
    map.put("E", "eee");
    map.put("F", "fff");
     
    String key = "D";
    String value = "eee";
    if(map.containsKey(key)){
        System.out.println("find key ["+key+"]");
    }else{
        System.out.println("not find key ["+key+"]");
    }
    if(map.containsValue(value)){
        System.out.println("find value ["+value+"]");
    }else{
        System.out.println("not find value ["+value+"]");
    }
}


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

find key [D]
find value [eee]

728x90