【发布时间】:2019-02-14 16:25:42
【问题描述】:
在代码中,我想通过map()方法修改变量i:
Integer[] seq = {1, 3, 4, 1, 8, 11};
List<Integer> seqInt = Arrays.asList(seq);
List<Integer> seqFiltered = seqInt.stream().filter(i -> i%2!=0)
.map(i -> i++)
.collect(Collectors.toList());
System.out.println(seqFiltered);
但是,它输出[1, 3, 1, 11] 而不是[2, 4, 2, 12],后者可以从map(i -> i+1) 获得
【问题讨论】:
-
除了 nullpointer 的答案以获取更多详细信息:Is there a difference between x++ and ++x in java?
标签: java java-stream