本文整理匯總了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();
}