# Collections (Rust) > Vec, String, HashMap, HashSet, iterators, collect, ownership with collections - 20 interview questions - Junior - [Interview Questions: Rust](https://sharpskill.dev/en/technologies/rust/interview-questions.md) ## 1. Which method allows adding an element to the end of a Vec? **Answer** The push() method adds an element to the end of the vector, increasing its size by 1. This operation has amortized O(1) complexity because the vector may need to reallocate memory if capacity is exceeded. To add multiple elements, extend() or append() can be used depending on the needs. ## 2. What is the main difference between String and &str in Rust? **Answer** String is an owned type stored on the heap, mutable and resizable. &str is an immutable reference to a UTF-8 sequence, often called a 'string slice'. String owns its data and can be modified, while &str borrows existing data without owning it. This distinction is fundamental for memory management in Rust. ## 3. How to create a new empty Vec in Rust? **Answer** Vec::new() creates an empty vector without initial allocation. The vec![] macro can also create an empty vector, but Vec::new() is the standard explicit method. The generic type can be inferred or explicitly specified with turbofish syntax Vec::::new() or by type annotation. ## 17 more questions available - What does the get() method return on a Vec? - Which data structure to use for associating keys with values with O(1) average access? Sign up for free: https://sharpskill.dev/en/login ## Other Rust interview topics - [Rust Basics](https://sharpskill.dev/en/technologies/rust/interview-questions/rust-basics.md): 25 questions, Junior - [Ownership & Borrowing](https://sharpskill.dev/en/technologies/rust/interview-questions/ownership-borrowing.md): 22 questions, Junior - [Structs & Enums](https://sharpskill.dev/en/technologies/rust/interview-questions/structs-enums.md): 20 questions, Junior - [Error Handling](https://sharpskill.dev/en/technologies/rust/interview-questions/error-handling.md): 18 questions, Junior - [Modules & Packages](https://sharpskill.dev/en/technologies/rust/interview-questions/modules-packages.md): 18 questions, Junior - [Traits](https://sharpskill.dev/en/technologies/rust/interview-questions/traits.md): 22 questions, Mid-Level - [Generics](https://sharpskill.dev/en/technologies/rust/interview-questions/generics.md): 20 questions, Mid-Level - [Lifetimes](https://sharpskill.dev/en/technologies/rust/interview-questions/lifetimes.md): 20 questions, Mid-Level - [Iterators & Closures](https://sharpskill.dev/en/technologies/rust/interview-questions/iterators-closures.md): 22 questions, Mid-Level - [Smart Pointers](https://sharpskill.dev/en/technologies/rust/interview-questions/smart-pointers.md): 22 questions, Mid-Level - [Concurrency Basics](https://sharpskill.dev/en/technologies/rust/interview-questions/concurrency-basics.md): 20 questions, Mid-Level - [async/await](https://sharpskill.dev/en/technologies/rust/interview-questions/async-await.md): 22 questions, Mid-Level - [Testing](https://sharpskill.dev/en/technologies/rust/interview-questions/testing.md): 18 questions, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/en/technologies/rust/interview-questions/cargo-ecosystem.md): 18 questions, Mid-Level - [Pattern Matching](https://sharpskill.dev/en/technologies/rust/interview-questions/pattern-matching.md): 18 questions, Mid-Level - [Macros](https://sharpskill.dev/en/technologies/rust/interview-questions/macros.md): 20 questions, Mid-Level - [Serde & Serialization](https://sharpskill.dev/en/technologies/rust/interview-questions/serde-serialization.md): 20 questions, Mid-Level - [Unsafe Rust](https://sharpskill.dev/en/technologies/rust/interview-questions/unsafe-rust.md): 20 questions, Senior - [Advanced Traits](https://sharpskill.dev/en/technologies/rust/interview-questions/advanced-traits.md): 22 questions, Senior - [Advanced Lifetimes](https://sharpskill.dev/en/technologies/rust/interview-questions/advanced-lifetimes.md): 20 questions, Senior - [Type System](https://sharpskill.dev/en/technologies/rust/interview-questions/type-system.md): 20 questions, Senior - [Tokio & Async I/O](https://sharpskill.dev/en/technologies/rust/interview-questions/tokio-async.md): 22 questions, Senior - [Performance Optimization](https://sharpskill.dev/en/technologies/rust/interview-questions/performance-optimization.md): 20 questions, Senior - [Memory Management](https://sharpskill.dev/en/technologies/rust/interview-questions/memory-management.md): 20 questions, Senior - [Web Frameworks](https://sharpskill.dev/en/technologies/rust/interview-questions/web-frameworks.md): 22 questions, Senior - [Database Integration](https://sharpskill.dev/en/technologies/rust/interview-questions/database-integration.md): 20 questions, Senior - [Rust Design Patterns](https://sharpskill.dev/en/technologies/rust/interview-questions/design-patterns.md): 20 questions, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/en/technologies/rust/interview-questions/collections