Replace nested loop with Java 8 flatmap
问题 I'm trying to use flatmap to make a nested loop with the Stream API, but I can't seem to figure it out. As an example, I want to recreate the following loop: List<String> xs = Arrays.asList(new String[]{ "one","two", "three"}); List<String> ys = Arrays.asList(new String[]{"four", "five"}); System.out.println("*** Nested Loop ***"); for (String x : xs) for (String y : ys) System.out.println(x + " + " + y); I can do it like this, but this seems ugly: System.out.println("*** Nested Stream ***");