Streams
- Declarative/Functional wrapper to operative on data sources, to make bulk operations fast and quick.
- An interface not concrete implementation
Different ways to create a stream
- using
stream()
from collection
List<String> fruitsCollection = Arrays.asList("apple", \
"mango", \
"oranges", \
"grape", \
"guava");
Stream fruitsStream = fruitsCollection.stream();
Stream alphabetStream = Stream.of("a", "b", "c");
String[] fruitsArray = ["apple", "oranges", "mango"];
Stream fruitsStream = Arrays.stream(fruitsArray);
- using
stream.generate()
for infinite stream
Stream randomNumberStream = Stream.generate( () -> Math.random() );