How can I add the counter value to every nth item while iterating though a Stream?
Here is my simplest code:
Stream.of("a1","a2","a3")
.map(x -> x + "counterValue")
.findFirst()
.ifPresent(System.out::println);
As I am adding "counterValue" string with every n
th item, what I want to achieve is to add the i
th value with every nth element.
The current program gives the output as a1counterValue
.
I want the output as a10
. 0 mean the index of that element.
Can anybody please help?