Trying to release java 8 threads. Is it possible in threads to find the number of elements starting with X, Y, Z, from a list that contains many 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 indicates the number of elements starting with X, Y, Z in the list, but in the above case I repeat three times to get the data. This can be done by looping through the list only once, using a simple loop. Is it possible to fulfill all these conditions in one thread (iterate only once) instead of using multiple threads?
Any help is greatly appreciated.
Vicky source
share