Back
Close

How to apply a function on each element of a List in Java

[CG]BOUGA
3,057 views
// {...}
List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> newIntegers = integers.stream()
.filter(i -> i <= 3)
.map(i -> 2*i)
.collect(Collectors.toList());
System.out.println(newIntegers);
// {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants