How to find the longest string in a vector of strings in Rust

1 Answer

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



  
/*
run:

python

*/

 



answered Oct 2, 2024 by avibootz
...