forked from int28h/JavaTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.java
More file actions
21 lines (15 loc) · 1020 Bytes
/
19.java
File metadata and controls
21 lines (15 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
Write a collector that partitions all words in a stream into two groups: palindromes (true) and usual words (false).
The collector should return Map<Boolean, List<String>>. All input words will be in the same case (lower).
Let's remind, a palindrome is a word or phrase which reads the same backward or forward, such as noon or level.
In our case, a palindrome is always a word. For details, see https://en.wikipedia.org/wiki/Palindrome
Hint: the method reverse() of StringBuilder may help you.
Important. You should write only the collector in any valid formats but without ; on the end.
It will be passed as an argument to the collect() method of a stream as shown below.
String[] words = ...
Map<Boolean, List<String>> palindromeOrNoMap =
Arrays.stream(words)
.collect(...your_collector_will_be_passed_here...);
Examples of the valid solution formats: Collectors.reducing(...) or reducing(...)
*/
Collectors.partitioningBy(a -> a.equals(new StringBuilder(a).reverse().toString()))