Developer J

containsKey containsValue (Map에 Key, Value 값 있는지 확인) 본문

개발자 되기 part1/Java

containsKey containsValue (Map에 Key, Value 값 있는지 확인)

Developer J 2022. 2. 2. 23:32
반응형

containsKey

Map에 해당 Key가 있으면 True, 없다면 False를 반환

 

public class test {
	public static void main(String[] args) {
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("A","JAVA");
		hashMap.put("B","PYTHON");
		
		System.out.println(hashMap.containsKey("A"));
		System.out.println(hashMap.containsKey("C"));
	}
}
/////Console/////
true
false

 

containsValue

Map에 해당 Value가 있으면 True, 없다면 False를 반환

 

public class test {
	public static void main(String[] args) {
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("A","JAVA");
		hashMap.put("B","PYTHON");
        
		System.out.println(hashMap.containsValue("JAVA"));
		System.out.println(hashMap.containsValue("GO"));
	}
}
/////Console/////
true
false
반응형