JAVA STREAMS INTRESTED TO LEARN

IntStream.rangeClosed(0, 10).forEach(num -> System.out.print(num));
 
Output
 
0
1
2
3
4
5
6
7
8
9
10
 
 
IntStream.range(0, 10).forEach(num -> System.out.print(num)); 
O/P
0
1
2
3
4
5
6
7
8
9
Stream.of("This", "is", "Java8", "Stream").forEach(System.out::println);
O/P 
This
is
Java8
Stream


String[] stringArray = new String[] { "Streams", "can", "be", "created", "from", "arrays" };
Arrays.stream(stringArray).forEach(System.out::println);
O/P
 
Streams
can
be
created
from
arrays
 
List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);

IntSummaryStatistics stats = numbers.stream().mapToInt((x) -> x).summaryStatistics();
 

System.out.println(stats.getAverage());
System.out.println(stats.getCount());
System.out.println(stats.getMax());
System.out.println(stats.getMin());
System.out.println(stats.getSum()); 
 
O/P 
3.5714285714285716
7
7
2
25
 


Comments

Popular posts from this blog

How whatsapp works

Android N Developer Preview? It's exciting for most of you