I am trying sequential search using Java 8 streams and lambda expressions. Here is my code
List<Integer> list = Arrays.asList(10, 6, 16, 46, 5, 16, 7);
int search = 16;
list.stream().filter(p -> p == search).forEachOrdered(e -> System.out.println(list.indexOf(e)));
Output: 2
2
I know list.indexOf(e)
always prints the index of the first occurrence. How do I print all the indexes?