package jp.co.confrage; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class Sample { | |
public static void main(String[] args) { | |
List<Integer> a = Arrays.asList(10, 100); | |
List<Integer> b = Arrays.asList(1, 3, 5); | |
List<Integer> c = Arrays.asList(2, 4, 6); | |
List<List<Integer>> nestedlist = Arrays.asList(a, b, c); | |
System.out.println(nestedlist); // [[10, 100], [1, 3, 5], [2, 4, 6]] | |
List<Integer> flatten = | |
nestedlist.stream().flatMap(x -> x.stream()).collect(Collectors.toList()); | |
System.out.println(flatten); // [10, 100, 1, 3, 5, 2, 4, 6] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment