-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (37 loc) · 1.4 KB
/
Copy pathMain.java
File metadata and controls
44 lines (37 loc) · 1.4 KB
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
39
40
41
42
43
44
package library.streamapi.example5;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Created by orifjon9 on 3/17/2017.
*/
public class Main {
public static void main(String[] args) {
//[{“A”, “B”}, {“D”}, {“1”, “3”, “5”}]
Set<String> set1 = Stream.of(new String[]{"A", "B"}).collect(Collectors.toSet());
Set<String> set2 = Stream.of(new String[]{"D"}).collect(Collectors.toSet());
Set<String> set3 = Stream.of(new String[]{"1", "2", "3"}).collect(Collectors.toSet());
List<Set<String>> sets = Arrays.asList(set1, set2, set3);
List<String> lists = sets.stream()
.map(set -> set.stream().collect(Collectors.toList()))
.reduce((x, y) -> joinTwoArray(x, y))
.get();
System.out.println(lists);
}
public static List<String> joinTwoArray(List<String> firstList, List<String> secondList) {
ArrayList<String> list = new ArrayList<>();
list.addAll(firstList);
list.addAll(secondList);
return list;
}
/*
public static <T> List<T> joinTwoArrayGeneric(List<T> firstList, List<T> secondList) {
ArrayList<T> list = new ArrayList<>();
list.addAll(firstList);
list.addAll(secondList);
return list;
}*/
}