-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInspiringStrings.java
More file actions
31 lines (25 loc) · 884 Bytes
/
InspiringStrings.java
File metadata and controls
31 lines (25 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.smlnskgmail.jaman.codewarsjava.kyu7;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
// https://www.codewars.com/kata/5939ab6eed348a945f0007b2
public class InspiringStrings {
private final String input;
public InspiringStrings(String input) {
this.input = input;
}
public String solution() {
List<String> words = Arrays.asList(input.split(" "));
int maxLength = Collections.max(
words,
Comparator.comparingInt(String::length)
).length();
List<String> wordsWithMaxLength = words
.stream()
.filter(w -> w.length() == maxLength)
.collect(Collectors.toList());
return wordsWithMaxLength.get(wordsWithMaxLength.size() - 1);
}
}