Demo entry 5354673

Converting a Vec to a HashMap

   

Submitted by Lee Jenkins on Jun 17, 2016 at 23:47
Language: Rust. Code size: 401 Bytes.

use std::collections::HashMap;

fn main() {
    let map: HashMap<i32, i32> = vec![(1, 2), (3, 4)].into_iter().collect();
    for (x, y) in map {
        println!("{} -> {}", x, y);
    }


    let mut map: HashMap<i32, i32> = HashMap::new();
    for i in 1..11 {
        map.insert(i, i * i);
    }
    println!("");
    for (x, y) in map {
        println!("{} -> {}", x, y);
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).