- how to create hashmap in rust?
use std::collections::HashMap;
let a = HashMap::new();
let a2= HashMap::from([
("key","value"),
("key","value")
]);
- how to insert ("key","value") into map instance?
let a2= HashMap::from([
("key","value"),
("key","value")
]);
a2.insert("dd","22")
3.how to remove someone out of map instance?
map.remove(&String::from("color2"));
4.how to update value of key?
map.entry("test2").or_insert(200);
5.how to get value of key?
let val= map.get("test2");
- how to traverse map instance?
let mut a2= HashMap::from([
("key","value"),
("key","value")
]);
for (key,value) in &mut a2{
value*="213"
};
Top comments (0)