Skip to content
Quiz · Collections · lesson 10 of 10

Quiz — counting with entry

What does the program print?

Rust
use std::collections::HashMap;

fn main() {
    let mut counts = HashMap::new();
    for w in "a b a c a".split_whitespace() {
        *counts.entry(w).or_insert(0) += 1;
    }
    println!("{} {}", counts["a"], counts["c"]);
}