Wednesday, October 26, 2016

Problem No: #13 How to Print Sorted list of Random Numbers using Stream?

Java 8 :: Streams and Lambda Expressions

/*
 * Problem No: #13
 * Problem Definition: How to Print Sorted list of Random Numbers using Stream?
 * 
 * Answer: By Using, 
 * > java.util.Collection.stream(): Returns a sequential Stream with this collection as its source. 
 *  
 *> java.util.stream.Stream.forEach(): Performs an action for each element of this stream.This is a "terminal operation". 
 * 
 * **Same Operations can be applied with LongStream and DoubleStream
 * Program By: Mr.DIpak SOnar
 * Date : 26th Oct 2016
 */

import java.util.Random;

public class StreamsRandomSortedEx {

public static void main(String[] args) {
Random random = new Random();

random.ints().limit(10).sorted().forEach(System.out::println);
}
}

No comments:

Post a Comment