HashMapの値を変更2022/2/19 11:17:00 insertを2回使うhashmap.insert(String::from("Blue"), 10); hashmap.insert(String::from("Blue"), 50); println!("{:?}", hashmap) // {"Blue": 50} もしくはget_mutを使うlet key = String::from("Blue"); if let Some(v) = hashmap.get_mut(&key) { *v=100; } if let Some(v) = hashmap.get(&key) { println!("{}", v); //100 }
HashMapに要素を追加2022/2/19 9:03:00 //hashmap.insert(key, value); hashmap.insert(String::from("Blue"), 10); hashmap.insert(String::from("Yellow"), 50);