3 回答
TA贡献1801条经验 获得超16个赞
pairMap
int[] pairwiseDiffs = IntStreamEx.of(input).pairMap((a, b) -> (b-a)).toArray();
Pair
Pair
Stream<Pair> pairs = IntStreamEx.of(input).boxed().pairMap(Pair::new);
Stream
:
Stream<Pair> pairs = StreamEx.of(stream).pairMap(Pair::new);
TA贡献1789条经验 获得超10个赞
arrayList
IntStream.range(1, arrayList.size()) .mapToObj(i -> new Pair(arrayList.get(i-1), arrayList.get(i))) .forEach(System.out::println);
TA贡献1752条经验 获得超4个赞
Stream<Pair> pairStream = Stream.iterate(0, (i) -> i + 1).map( // natural numbers new Function<Integer, Pair>() { Integer previous; @Override public Pair apply(Integer integer) { Pair pair = null; if (previous != null) pair = new Pair(previous, integer); previous = integer; return pair; } }).skip(1); // drop first null
pairStream.limit(1_000_000).forEach(i -> System.out.println(i));
P.S.(partition 2 1 stream)
添加回答
举报