代码
提交代码
import java.util.List; import java.util.Arrays; import java.util.stream.Collectors; public class Test{ public static void main(String...s){ List<String> nameA = Arrays.asList("Mahela", "Sanga", "Dilshan"); List<String> nameB = Arrays.asList("Misbah", "Afridi", "Shehzad"); List<List<String>> nameSets = Arrays.asList(nameA,nameB); List<String> flatMapList = nameSets.stream() .flatMap(pList -> pList.stream()) .collect(Collectors.toList()); System.out.println(flatMapList); } }
运行结果