This code returns the length of the longest String in a list of Strings. I have two solutions of which one works and the other doesn't
Correct
System.out.println(listOfConsecutiveOneStrings.stream()
.max(Comparator.comparing(String::length))
.max(Comparator.comparing(String::length))
.map(onesSequence -> onesSequence.length())
.get());
Wrong
System.out.println(listOfConsecutiveOneStrings.stream()
.max(Comparator.comparing(String::length))
.map(onesSequence -> onesSequence.length())
.max(Integer::max)
.get());
Why is the first snippet correct and the second one incorrect?