Can I use stream to check, which 2 consecutive strings have the biggest sum of their lengths?
For example I have 5 valid usernames and I should print only Johnny and Frank:
String line = "James Jack Johnny Frank Bob";
String regexForValidUserName = "[a-zA-Z][a-zA-Z0-9_]{2,24}";
Pattern patternForUserName = Pattern.compile(regexForValidUserName);
Matcher matcherForUserName = patternForUserName.matcher(line);
List<String> listOfUsers = new LinkedList<>();
if (matcherForUserName.find()) {
listOfUsers.add(matcherForUserName.group());
}
listOfUsers.stream().map((a,b,c,d) -> a.length + b.length > c.length + d.length).foreach(System.out::println);