map each element in a List - Java java.util

Java examples for java.util:List Element

Description

map each element in a List

Demo Code


//package com.java2s;
import java.util.LinkedList;
import java.util.List;

import java.util.function.Function;

public class Main {

    public static <T, R> List<R> map(List<T> list, Function<T, R> function) {
        List<R> mapped = new LinkedList<>();

        for (T entry : list) {
            mapped.add(function.apply(entry));
        }/*  www .  jav a2s. c o  m*/

        return mapped;
    }
}

Related Tutorials