本文整理了Java中java.util.stream.LongStream.iterate()
方法的一些代码示例,展示了LongStream.iterate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.iterate()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:iterate
暂无
代码示例来源:origin: poetix/protonpack
/**
* Constructs an infinite (although in practice bounded by Long.MAX_VALUE) stream of longs 0, 1, 2, 3...
* for use as indices.
* @return A stream of longs.
*/
public static LongStream indices() {
return LongStream.iterate(0L, l -> l + 1);
}
代码示例来源:origin: com.codepoetics/protonpack
/**
* Constructs an infinite (although in practice bounded by Long.MAX_VALUE) stream of longs 0, 1, 2, 3...
* for use as indices.
* @return A stream of longs.
*/
public static LongStream indices() {
return LongStream.iterate(0L, l -> l + 1);
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public LongStream numbers() {
return iterate(2, i -> i + 1)
.filter(Prime::isPrime);
}
public static void main(String[] args) {
代码示例来源:origin: hazelcast/hazelcast-jet
/**
* Returns a stream of {@code long}s:
* {@code for (long i = start; i <= end; i += step) yield i;}
*/
private static LongStream range(long start, long end, long step) {
return start > end
? LongStream.empty()
: LongStream.iterate(start, n -> n + step).limit(1 + (end - start) / step);
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
static long[] fillCounted(int size) {
return LongStream.iterate(0, i -> i + 1)
.limit(size).toArray();
}
public static void main(String[] args) {
代码示例来源:origin: com.aol.cyclops/cyclops-base
/**
* Add an index to the current Stream
*
* <pre>
* {@code
* assertEquals(asList(new Pair("a", 0L), new Pair("b", 1L)), of("a", "b").zipWithIndex().toList());
* }
* </pre>
*/
public final SequenceM<Pair<T,Long>> zipWithIndex(){
return zipStream(LongStream.iterate(0, i->i+1),(a,b)->new Pair<>(a,b));
}
/**
代码示例来源:origin: com.aol.cyclops/cyclops-streams
/**
* Add an index to the current Stream
*
* <pre>
* {@code
* assertEquals(asList(new Tuple2("a", 0L), new Tuple2("b", 1L)), of("a", "b").zipWithIndex().toList());
* }
* </pre>
*/
public final SequenceM<Tuple2<T,Long>> zipWithIndex(){
return zipStream(LongStream.iterate(0, i->i+1),(a,b)->new Tuple2<>(a,b));
}
/**
代码示例来源:origin: com.aol.cyclops/cyclops-core
public LongStream asLongRange(){
long start = ((Number)t3.v1()).longValue();
long end = ((Number)t3.v2()).longValue();
long step = ((Number)t3.v3()).longValue();
return LongStream.iterate(start, i -> i + step)
.limit((end-start)/step);
}
}
代码示例来源:origin: com.aol.cyclops/cyclops-tuples
public LongStream asLongRange(){
long start = ((Number)t3.v1()).longValue();
long end = ((Number)t3.v2()).longValue();
long step = ((Number)t3.v3()).longValue();
return LongStream.iterate(start, i -> i + step)
.limit((end-start)/step);
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args)
throws IOException {
Timer timer = new Timer();
List<String> primes =
iterate(2, i -> i + 1)
.parallel() // [1]
.filter(ParallelPrime::isPrime)
.limit(COUNT)
.mapToObj(Long::toString)
.collect(Collectors.toList());
System.out.println(timer.duration());
Files.write(Paths.get("primes.txt"), primes,
StandardOpenOption.CREATE);
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(CHECK);
timeTest("Sum Stream", CHECK, () ->
LongStream.rangeClosed(0, SZ).sum());
timeTest("Sum Stream Parallel", CHECK, () ->
LongStream.rangeClosed(0, SZ).parallel().sum());
timeTest("Sum Iterated", CHECK, () ->
LongStream.iterate(0, i -> i + 1)
.limit(SZ+1).sum());
// Slower & runs out of memory above 1_000_000:
// timeTest("Sum Iterated Parallel", CHECK, () ->
// LongStream.iterate(0, i -> i + 1)
// .parallel()
// .limit(SZ+1).sum());
}
}
代码示例来源:origin: apache/incubator-ratis
@Test(timeout = 1000)
public void testMinMax() {
runTestMinMax(LongStream.empty());
runTestMinMax(LongStream.iterate(0, n -> n).limit(10));
for(int count = 1; count < 10; count++) {
runTestMinMax(LongStream.iterate(1, n -> n + 1).limit(count));
}
for(int count = 1; count < 10; count++) {
runTestMinMax(LongStream.iterate(0, _dummy -> ThreadLocalRandom.current().nextLong()).limit(count));
}
}
内容来源于网络,如有侵权,请联系作者删除!