当前位置: 首页>>代码示例>>Java>>正文


Java List.parallelStream方法代码示例

本文整理汇总了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;
}
 
开发者ID:dakaraphi,项目名称:eclipse-plugin-commander,代码行数:13,代码来源:InternalContentProviderProxy.java

示例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


注:本文中的java.util.List.parallelStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。