import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; import java.util.Locale; public class _1 { public static void main(String[] args) { // List<String> funs = new ArrayList<String>(); // funs.add("F"); // funs.add("U"); // funs.add("N"); // funs.stream().forEach(x->System.out.println(x)); // funs.stream().map(x->x+"001").forEach(x->System.out.println(x)); //第一个结果是FUN 第二个结果是F001 U001 N001; List<String> fun1=new ArrayList<>(); fun1.add("one"); fun1.add("two"); fun1.add("three"); List<String> fun2=new ArrayList<>(); fun2.add("four"); fun2.add("five"); fun2.add("six"); List<List<String>> nestedList = new ArrayList<>(); nestedList.add(fun1); nestedList.add(fun2); // nestedList.stream().map(x->{return x.stream().map(a->a.toUpperCase());}).forEach(x->x.forEach(a->System.out.println(a))); //结果是 ONE TWO THREE FOUR FIVE SIX 太麻烦了! //简化结果//nestedList.stream().flatMap(x->x.stream()).map(x->x.toUpperCase()).forEach(s->System.out.print(s)); } }
标签:map,flatmap,Java,funs,stream,fun2,add,fun1 From: https://www.cnblogs.com/heshijinghuang/p/16716925.html