I created simple demo :
public static void main(String[] args) {
List<String> list2 = Arrays.asList("adf", "bcd", "abc", "hgr", "jyt", "edr", "biu");
String collect = list2.stream().collect(String::new, (res, elem) -> {
res=res.concat(" ").concat(elem);
// System.out.printf("res=%s, elem=%s\n", res.isEmpty(), elem);
}, (res1, res2) -> {
System.out.printf("res1=%s, res2=%s\n", res1, res2);
});
System.out.println("collect=" + collect);
}
The problem is that BiConsumer combiner
part of collect
doesn't run at all.
It runs if I use parallelStream()
but two arguments res1
and res2
are equal to supplier String::new
.
How to make combiner
work in collect
method?