Optional<Integer> opInt = Arrays.asList(s.split("\\s")).stream()
.map(l -> l.length())
.filter(l -> l % 2 == 0)
.sorted(Comparator.reverseOrder())
.findFirst();
System.out.println(opInt.get());
Have written code above for that. Can we write concise code for it.
Instead of using
Arrays.asList().stream(), useArrays.stream(…).You can use method reference instead of using the lambda.
l -> l.length().You can replace
.sorted(Comparator.reverseOrder())with a.max()Refactored Code: