import
java.io.IOException;
import
java.lang.String;
import
java.nio.file.*;
import
java.util.*;
import
java.util.Arrays;
import
java.util.List;
import
java.util.stream.*;
class
GFG {
public
static
void
main(String[] args)
throws
IOException
{
System.out.println(
"Integer Stream : "
);
IntStream.range(
1
,
10
).forEach(System.out::print);
System.out.println();
System.out.println(
"Integer Stream with skip : "
);
IntStream.range(
1
,
10
).skip(
5
).forEach(
x -> System.out.println(x));
System.out.println();
System.out.println(
"Integer Stream with sum : "
);
System.out.println(IntStream.range(
1
,
5
).sum());
System.out.println();
System.out.println(
"Stream.of, sorted and findFirst : "
);
Stream.of(
"Java "
,
"Scala "
,
"Ruby "
)
.sorted()
.findFirst()
.ifPresent(System.out::println);
System.out.println();
String[] names = {
"AI"
,
"Matlab"
,
"Scikit"
,
"TensorFlow"
,
"OpenCV"
,
"DeepLearning"
,
"NLP"
,
"NeuralNetworks"
,
"Regression"
};
System.out.println(
"Stream from Array, sort, filter and print : "
);
Arrays
.stream(names)
.filter(x -> x.startsWith(
"S"
))
.sorted()
.forEach(System.out::println);
System.out.println();
System.out.println(
"Average of squares of an int array : "
);
Arrays.stream(
new
int
[] {
2
,
4
,
6
,
8
,
10
})
.map(x -> x * x)
.average()
.ifPresent(System.out::println);
System.out.println();
System.out.println(
"Stream from List, filter and print : "
);
List<String> people = Arrays.asList(
"AI"
,
"Matlab"
,
"Scikit"
,
"TensorFlow"
,
"OpenCV"
,
"DeepLearning"
,
"NLP"
,
"NeuralNetworks"
);
people.stream()
.map(String::toLowerCase)
.filter(x -> x.startsWith(
"a"
))
.forEach(System.out::println);
System.out.println();
System.out.println(
"Reduction - sum : "
);
double
total
= Stream.of(
7.3
,
1.5
,
4.8
)
.reduce(
0.0
,
(Double a, Double b) -> a + b);
System.out.println(
"Total = "
+ total);
System.out.println();
System.out.println(
"Reduction - summary statistics : "
);
IntSummaryStatistics summary
= IntStream.of(
7
,
2
,
19
,
88
,
73
,
4
,
10
)
.summaryStatistics();
System.out.println(summary);
System.out.println();
}
}