Simple challenge - eliminate all bugs from the supplied code so that the code runs and outputs the expected value. Output should be the length of the longest word, as a number.
There will only be one ‘longest’ word.
1:
public static int findLongest(final String str){
return Arrays.stream(str.split(" ")).mapToInt(i->i.length()).max().getAsInt();
}
2:
public static int findLongest(final String str){
return stream.of(str.split(" ")).mapToInt(i->i.length()).max().getAsInt();
}
3:
return Stream.of(str.split(" ")).mapToInt(String::length).max().orElse(0);