Home >Java >javaTutorial >How to use Stream to operate elements in Java?
Explanation
1. java.util.Stream represents a series of elements that can perform one or more operations.
2. Stream operation can be an intermediate operation or a terminal operation. Terminal operations return results of a certain type. The intermediate operation returns the Stream object itself, and you can continue to call other method chains in the same line of code.
Instance
Collections have been extended in Java8, which can create Stream objects through Collection.stream() or Collection.parallelStream().
List<String> stringCollection = new ArrayList<>(); stringCollection.add("ddd2"); stringCollection.add("aaa2"); stringCollection.add("bbb1"); stringCollection.add("aaa1"); stringCollection.add("bbb3"); stringCollection.add("ccc"); stringCollection.add("bbb2"); stringCollection.add("ddd1");
The above is the detailed content of How to use Stream to operate elements in Java?. For more information, please follow other related articles on the PHP Chinese website!