本文整理匯總了Java中java.util.List.parallelStream方法的典型用法代碼示例。如果您正苦於以下問題:Java List.parallelStream方法的具體用法?Java List.parallelStream怎麽用?Java List.parallelStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.List
的用法示例。
在下文中一共展示了List.parallelStream方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setTableEntries
import java.util.List; //導入方法依賴的package包/類
public InternalContentProviderProxy<U> setTableEntries(List<RankedItem<U>> tableEntries) {
// TODO optimize and only create a stream when necessary
Stream<RankedItem<U>> tableStream = tableEntries.parallelStream();
if (sortResolverFn != null) {
tableStream = sortResolverFn.apply(tableStream);
}
tableStream = applyFilters(tableStream);
this.tableEntries = tableStream.collect(Collectors.toList());
return this;
}
示例2: main
import java.util.List; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
//Creating Streams using user/programmatically specified elements
Stream<String> Userstream = Stream.of("Creating","Streams","from","Specific","elements");
Userstream.forEach(p -> System.out.println(p));
//Creating Streams using array of objects
Stream<String> ArrayStream = Stream.of( new String[]{"Stream","from","an","array","of","objects"} );
ArrayStream.forEach(p -> System.out.println(p));
//Creating Streams from an array
String[] StringArray=new String[]{"We","can","convert","an","array","to","a","Stream","using","Arrays","as","well"};
Stream<String> StringStream=Arrays.stream(StringArray);
StringStream.forEach(p -> System.out.println(p));
//Creating Streams from Collection
List<Double> myCollection = new ArrayList<>();
for(int i=0; i<10; i++){
myCollection.add(Math.random());
}
//sequential stream
Stream<Double> sequentialStream = myCollection.stream();
sequentialStream.forEach(p -> System.out.println(p));
//parallel stream
Stream<Double> parallelStream = myCollection.parallelStream();
parallelStream.forEach(p -> System.out.println(p));
//Stream from Hashmap
Map<String, Integer> mapData = new HashMap<>();
mapData.put("This", 1900);
mapData.put("is", 2000);
mapData.put("HashMap", 2100);
mapData.entrySet()
.stream()
.forEach(p -> System.out.println(p));
mapData.keySet()
.stream()
.forEach(p-> System.out.println(p));
//primitive streams
IntStream.range(1, 4)
.forEach(p -> System.out.println(p));
LongStream.rangeClosed(1, 4)
.forEach(p -> System.out.println(p));
DoubleStream.of(1.0,2.0,3.0,4.0)
.forEach(p -> System.out.println(p));
//Infinite Streams using generate()
Stream <Double> sequentialDoubleStream = Stream.generate(Math :: random);
Stream<Integer> sequentialIntegerStream = Stream.generate(new AtomicInteger () :: getAndIncrement);
//Infinite Streams using iterate()
Stream <Integer> sequentialIntegerStream1 = Stream.iterate (Integer.MIN_VALUE, i -> i++);
Stream <BigInteger> sequentialBigIntegerStream = Stream.iterate(BigInteger.ZERO, i -> i.add (BigInteger.TEN));
//Streams from File
Stream<String> streamOfStrings = Files.lines(Paths.get("Apology_by_Plato.txt"));
Stream<String> streamWithCharset = Files.lines(Paths.get("Apology_by_Plato.txt"), Charset.forName("UTF-8"));
}
開發者ID:PacktPublishing,項目名稱:Apache-Spark-2x-for-Java-Developers,代碼行數:72,代碼來源:CreateStreamExample.java