relatively new to java and am looking into Streams
I was wondering how I can convert a Stream of Integers based on conditions.
For example, my stream will look something like 1,2,3,4,5
and I want to iterate and check if the next number is 3. If it is, i will add 1, else i will return 0.
Thereafter, convert it into a List of Integers which will look like:
[0,3,0,0,0]
What i currently have is something like this:
List<Integer> lst = new List.of(1,2,3,4,5);
Stream<Integer> strlst = lst.stream();
strlst.forEach(x -> {if (x.get(x+1).equals(3)) { return x + 1 } else {return 0} });
strlst.toList();