The source code to create a simple HashSet is given below. The given program is compiled and executed successfully.
// Rust program to create a
// simple HashSet
use std::collections::HashSet;
fn main() {
let mut set:HashSet<i32> = HashSet::new();
set.insert(10);
set.insert(20);
set.insert(30);
set.insert(40);
println!("HashSet:\n{:?}",set);
}
Output:
HashSet:
{10, 30, 20, 40}
Explanation:
Here, we created a HashSet to store integer items. Then we inserted items into HashSet using the insert() function and printed HashSet.
Program/Source Code:
The source code to create a simple HashSet is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created a HashSet to store integer items. Then we inserted items into HashSet using the insert() function and printed HashSet.
need an explanation for this answer? contact us directly to get an explanation for this answer