applying the Function to each element of the original List - Java Lambda Stream

Java examples for Lambda Stream:Function

Description

applying the Function to each element of the original List

Demo Code


import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class Main {

  public static <T, U> List<U> map(List<T> list, Function<? super T, ? extends U> f) {

    List<U> rlt = new ArrayList<>();
    list.forEach(t -> rlt.add(f.apply(t)));
    return rlt;//from  w  ww  .  ja  v a 2 s  . c om
  }
}

Related Tutorials