Trying out java 8 streams . Is it possible in streams to find the count of elements starting with X , Y , Z from a List which contains a lot of elements.
transactions.stream()
.filter(e -> startsWith("X"))
.count();
transactions.stream()
.filter(e -> startsWith("Y"))
.count();
transactions.stream()
.filter(e -> startsWith("Z"))
.count();
The above code gives the count of elements starting with X,Y,Z in the list but in the above case i'am iterating through the list three times to get the data's. This could be done by iterating the list just once using a simple for loop. Is it possible to do all these conditions in a single stream [iterating just once] instead of using multiple streams ?
Any help is greatly appreciated.