以下代碼輸出總是24。爲什麼Combiner不會對輸出產生影響?
public static void main(String[] args) throws InterruptedException {
List<String> list = new ArrayList<String>();
list.add("java");
list.add("php");
list.add("python");
list.add("perl");
list.add("c");
list.add("lisp");
list.add("c#");
int s = list.stream().reduce(0, (x, y) -> x + y.length(), (x, y) -> 0);
System.out.println(s);
s = list.stream().reduce(0, (x, y) -> x + y.length(), (x, y) -> x - y);
System.out.println(s);
s = list.stream().reduce(0, (x, y) -> x + y.length(), (x, y) -> x * y);
System.out.println(s);
}
問題是爲什麼組合器影響我的代碼。如果減少並行Stream
你能解釋更多關於** combiner.apply(u,accumulator.apply(identity,t))== accumulator.apply(u,t)** ?? –
@HasnainAliBohra https://stackoverflow.com/questions/45054372/what-do-the-stream-reduce-requirements-exactly-entail/45054892#45054892 – Eugene
由於我是具有相同疑問形成同一OCJP book.Im問句子>>意思是u和什麼表達** combiner.apply(U,accumulator.apply(身份,t))的**是 –