Stream represents a sequence of objects from a source, which supports aggregate operations.
Basic Points of Streams :
- Not a data structure
- Designed for lambdas
- Do not support indexed access
- Can easily be outputted as arrays or lists
- Lazy access supported
- Parallelizable
Stream.of(val1, val2, val3….)
public class StreamBuilders {public static void main(String[] args) {
Stream
stream.forEach(p -> System.out.println(p));
}
}
Stream.of(arrayOfElements)
public class StreamBuilders {public static void main(String[] args) {
Stream
stream.forEach(p -> System.out.println(p));
}
}
List.stream()
public class StreamBuilders {public static void main(String[] args) {
List
for(int i = 1; i< 10; i++) {
list.add(i);
}
Stream
stream.forEach(p -> System.out.println(p));
}
}
Stream.generate() or Stream.iterate()
public class StreamBuilders {public static void main(String[] args) {
Stream
stream.forEach(p -> System.out.println(p));
}
}
String chars or String Tokens (First Model)
public class StreamBuilders {public static void main(String[] args) {
IntStream stream = "12345_abcdefg".chars();
stream.forEach(p -> System.out.println(p));
}
}
String chars or String Tokens (Second Model)
public class StreamBuilders {public static void main(String[] args) {
Stream
stream.forEach(p -> System.out.println(p));
}
}