本文整理汇总了Java中java.util.stream.IntStream.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java IntStream.forEach方法的具体用法?Java IntStream.forEach怎么用?Java IntStream.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.IntStream
的用法示例。
在下文中一共展示了IntStream.forEach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRandomStream
import java.util.stream.IntStream; //导入方法依赖的package包/类
/**
* Random类提供的随机数字流
*/
@Test
public void testRandomStream() {
IntStream intStream = new Random().ints();
DoubleStream doubleStream = new Random().doubles();
LongStream longStream = new Random().longs();
/**
* ints(long streamSize, int randomNumberOrigin,int randomNumberBound)
* 10 表示这个流有几个数据
* 20,100 是生成的数据的范围
*/
IntStream stream = new Random().ints(10, 20, 100);
stream.forEach(System.out::println);
}
示例2: apply
import java.util.stream.IntStream; //导入方法依赖的package包/类
/**
* Returns a new list which is the result of applying the mapping function to values of the input list
* @param list the input list on which to apply the mapping function to all elements
* @param parallel true if parallel mapping should be used
* @param listMapper the list mapper function to apply to all values in input list
* @param <I> the input list type
* @param <O> the output list type
* @return the output list
*/
public static <I,O> List<O> apply(List<I> list, boolean parallel, ListMapper<I,O> listMapper) {
final int size = list.size();
final List<O> result = createList(list);
IntStream.range(0, size).forEach(i -> result.add(null));
final IntStream indexes = parallel ? IntStream.range(0, size).parallel() : IntStream.range(0, size);
indexes.forEach(index -> {
final I source = list.get(index);
final O target = listMapper.apply(index, source);
result.set(index, target);
});
return result;
}
示例3: ofInts
import java.util.stream.IntStream; //导入方法依赖的package包/类
/**
* Retruns the integer bounds of a stream of ints
* @param stream the stream to compute bounds on
* @return the bounds for stream, empty if no data in stream
*/
public static Optional<Bounds<Integer>> ofInts(IntStream stream) {
final OfInts calculator = new OfInts();
stream.forEach(calculator::add);
return calculator.getBounds();
}