Java Code Examples for java.util.List.parallelStream()

The following are Jave code examples for showing how to use parallelStream() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: eclipse-plugin-commander   File:   View Source Code Vote up 5 votes
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;
Example 2
Project: Apache-Spark-2x-for-Java-Developers   File:   View Source Code Vote up 4 votes
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"};
        StringStream.forEach(p -> System.out.println(p));
        //Creating Streams from Collection
        List<Double> myCollection = new ArrayList<>();
        for(int i=0; i<10; i++){
               //sequential stream
        Stream<Double> sequentialStream =;
        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);
       		.forEach(p -> System.out.println(p));
               .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));
        .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"));