Start learning free

LESSON 97 OF 348 · ARRAYS I

Updating vector elements in Rust in Rust

Lesson

The entries of vectors are mutable and can be changed freely, using indices and the bracket notation, just like we do with static arrays:

let mut names = vec!["Andy", "Mary", "Cody"];

names[0] = "Mircea";
names[2] = "Mike";

// names is now ["Mircea", "Mary", "Cody"]

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check

    Updating Elements in Rust

    Keep going with RustAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free