public static List map(List list, Function mapping) { | |
List result = new ArrayList(); | |
for (T elem : list) { | |
result.add(mapping.apply(elem)); | |
} | |
return result; | |
} | |
public static void main (String[] args) { | |
List inputList = | |
Arrays.asList("functional", "programming", "with", "closures"); | |
List mappedList = map(inputList, s -> s.length()); | |
System.out.println("Initial List: " + inputList); | |
System.out.println("Mapped List: " + mappedList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment