forked from Apress/functional-interfaces-in-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSect9_Ex2.java
More file actions
27 lines (25 loc) · 841 Bytes
/
Sect9_Ex2.java
File metadata and controls
27 lines (25 loc) · 841 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
package chapter12;
import java.util.function.*;
import java.util.*;
import java.util.stream.*;
public class Sect9_Ex2
{
public static void main(String[] args)
{
Supplier<List<Character>> supp = () -> new ArrayList<Character>();
BiConsumer<List<Character>, Character> acc = (x,y) -> {
System.out.print("acc: x=" + x + " y=" + y+ " result=");
if (Character.isAlphabetic(y))
x.add(0,y);
else
x.add(y);
x.forEach(z -> System.out.print(z));
System.out.println();
};
BiConsumer<List<Character>,List<Character>> comb2 = (x,y) ->
x.addAll(y);
Stream.of('1','a','b','2')
.collect(supp, acc, comb2)
.forEach(x -> System.out.println(x));
}
}