-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP17.java
More file actions
38 lines (32 loc) · 946 Bytes
/
P17.java
File metadata and controls
38 lines (32 loc) · 946 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
32
33
34
35
36
37
38
package lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Class for split list.
*/
public final class P17 {
private P17() {
}
/**
* Split one list of items into two sublist.
*
* @param list list to split
* @param nth point of split
* @param <T> type of item in list
* @return splitted list
*/
public static <T> Map<Boolean, List<T>> split(final List<T> list,
final int nth) {
Map<Boolean, List<T>> map = new HashMap<>();
map.put(true, IntStream.range(0, nth)
.mapToObj(list::get)
.collect(Collectors.toList()));
map.put(false, IntStream.range(nth, list.size()).
mapToObj(list::get)
.collect(Collectors.toList()));
return map;
}
}