Mutable vector of numbers, append (push) values
-
mut
-
push
-
append
-
We can make a vector mutable by using the
mut
keyword. -
We can append an element to the end of the vector using the
push
method.
fn main() { let mut numbers = vec![10, 11, 12]; println!("{}", numbers.len()); println!("{:?}", numbers); numbers.push(23); println!("{}", numbers.len()); println!("{:?}", numbers); }
3
[10, 11, 12]
4
[10, 11, 12, 23]