My Input Sequence is : [1,2,3,4,5]
Result should be : [1,12,3,14,5]
That is even numbers are incremented by 10, but odd values are left intact.
Here is what I tried:
public static List<Integer> incrementEvenNumbers(List<Integer> arrays){
List<Integer> temp =
arrays.stream()
.filter(x->x%2==0)
.map(i -> i+10)
.collect(Collectors.toList());
return temp;
}
when I call this method,
System.out.println(incrementEvenNumbers(Arrays.asList(1,2,3,4,5)));
I get [12, 14]
. I am wondering how to include the values not filtered
to seep in but the map
should not be applied for it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…