将一个类型的List转换为另一个类型的List

话不多说直接上代码:

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chaofan at 2018/7/12 16:48
 * email:[email protected]
 **/
public class ListTrans {
    private void test(){
        List list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        List strings = Lists.transform(list, new Function() {
            @Override
            public String apply(@Nullable Integer integer) {
                return integer.toString();
            }
        });
    }
}

你可能感兴趣的:(java)