: .
, , result collect(?,result,?,?).
# collect
combiner a BiConsumer<R,R>, , - 2 .
, , . - , . @Eugene .
a combiner . , . :
public class StreamCollectingTest {
@Test
public void combinerNeverBeCalledInSequentialStream() {
List<Integer> somearray = Arrays.asList(2, 4, 6, 8);
Map<String, Object> map = IntStream.range(0, 4).collect(
HashMap::new,
(result, it) -> result.put("test", somearray.get(it)),
(result1, result2) -> fail("Combiner was called in sequential stream!")
);
// maybe your logic is wrong, the size of map is always less than 2.
assertThat(map.keySet(), hasSize(1));
}
}