Java 8 got a brand new API called streams. it makes every developer’s life easy. Stream APIs are used to process the group of data. mostly streams are applied on collection objects but we can use stream with any group of data.
The followings are more widely used operations of streams:
- Iterate
- Filter
- Data Transformation
- Sorting
- Find Min and Max
- Count the data
- Much more…
Java Streams Methods
Java 8 Streams API has many methods but below are the most commonly used:
- filter()
- map()
- forEach()
- collect()
- count()
- distinct()
- sorted()
- toArray()
- flatMap()
- reduce()
We shall discuss each of the methods in detail. Remember that apart from the above methods Streams has many methods. Check out here.
Streams Creations
There are some ways to create a Stream in Java 8. We can create the stream using a group of data, Array or with Collections.
1. Create Empty Stream
Stream emptyStream = Stream.empty();
Stream.empty() method returns the empty stream object. This Empty Stream is used to avoid any null pointer exception.
2. Create Stream with Collection
List alpha = Arrays.asList("A","B","C","D");
Stream alphaStream = alpha.stream();
From Java 8 onwards, the Collection interface got a new method called stream() which returns with Stream object of that particular collection object.
In the above example, alpha is a collection object and we can get the stream of alpha using alpha.stream() method
3. Create Stream with Primitive Array
Stream alphaStream = Stream.of("USA","UK","Japan","China");
It is also possible to get stream for set of values using Stream.of() method. We can also convert the existing primitive array to stream.
For Example:
String[] strArr = new String[] {"Apple","Banana","Orange","Kiwi"};
Stream arrStream = Arrays.stream(strArr);
Conclusion
In this article, we have discussed the Streams API of the Java 8 version. Though we have given examples for beginners. we highly recommend reading more about other streams methods. You can check out here for more details. In the upcoming articles, we shall discuss all the methods of the stream with some examples. We would be happy if you leave your comments below.


Java 8: Introduction to Streams API
Java 8 got a brand new API called streams. it makes every developer’s life easy. Stream APIs are used to process the group of data. mostly streams are applied on collection objects but we can use stream with any group

Java 8: Consumer – Built-In Functional Interfaces
Consumer Interface is another Built-In Functional Interface of java.util.function package of Java 8. The consumer interface consumes the object and doesn’t return any object. it has only one abstract method called accept(). Along with this, it has one more default

Java 8: Supplier – Built-In Functional Interfaces
Supplier Interface is another Built-In Functional Interface of java.util.function package of Java 8. Supplier Interface used for assignment purposes. It has only one abstract method and doesn’t have any default or static method. Below is the get() method signature. It

Java 8: Predicate – Built-In Functional Interfaces
Predicate Interface is another Built-In Functional Interface of java.util.function package of Java 8. Predicate Interface can be used to evaluate the expression which returns the boolean result like true or false of the given expression. Example: Predicate logic = X

Java 8: Built-In Functional Interfaces. Supplier, Function, Predicate
Functional Interface was added in Java 8. Functional Interface is like a normal interface with only one abstract method. Remember, a Functional interface can have a default method but should have only one abstract method which is unimplemented. Also, @FunctionalInterface