■ HashMap 구조체의 get 메소드를 사용해 키 존재 여부를 구하는 방법을 보여준다.
▶ 예제 코드 (RS)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
use std::collections::HashMap; fn main() { let mut hashmap = HashMap::new(); hashmap.insert("A", 30); hashmap.insert("B", 50); if hashmap.get("D") == None { println!("D 키가 존재하지 않습니다.") } else { println!("D = {}", hashmap["D"]); } } |