- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1078.java
18 lines (16 loc) · 645 Bytes
/
_1078.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
packagecom.fishercoder.solutions.secondthousand;
importjava.util.stream.Collectors;
importjava.util.stream.IntStream;
publicclass_1078 {
publicstaticclassSolution1 {
publicString[] findOcurrences(Stringtext, Stringfirst, Stringsecond) {
String[] words = text.split(" ");
returnIntStream.range(0, words.length - 2)
.filter(i -> words[i].equals(first) && words[i + 1].equals(second))
.mapToObj(i -> words[i + 2])
.collect(Collectors.toList())
.stream()
.toArray(String[]::new);
}
}
}