How to find the longest string size of an array of strings in Rust

1 Answer

0 votes
fn main() {
    let strings = vec!["c++", "python", "c#", "rust", "swift", "java"];
    
    let longest_string_size = strings.iter().map(|s| s.len()).max().unwrap_or(0);
    
    println!("{}", longest_string_size);
}


  
/*
run:

6

*/

 



answered Oct 2, 2024 by avibootz
...