title: Java forEach not working on flatMap using IntStream.range
body: <p>Starting with this trivial example from java2s:</p>
  
  <pre><code> Stream.of("XML", "Java",  "CSS")
  .flatMap(name -&gt;  IntStream.range(0, name.length()).mapToObj(name::charAt))
  .forEach(System.out::println);
  </code></pre>
  
  <p>the output is</p>
  
  <pre><code>X
  M
  L
  J
  a
  v
  a
  C
  S
  S
  </code></pre>
  
  <p>I'm trying to understand what's going on inside the flatMap. I'd like to see the output of the IntStream.range, but I cannot get it to work. 
  It seems you can whack a forEach(SOP) onto an IntStream.range(a,b) but when it's inside of the flatMap function, that can't be done (and I didn't at first notice that the whole of <code>name -&gt;  IntStream.range(0, name.length()).mapToObj(name::charAt)</code> is the argument to the flatMap function.
  How could I use the flatMap function with IntStream.range to convert the strings to a sequence of numbers corresponding to the lengths of the words? </p>
  
  <p>I have tried this:</p>
  
  <pre><code> Stream.of("XML", "Java",  "CSS")
          .flatMap(name -&gt;  IntStream.range(0, name.length())) 
          .forEach(System.out::println);
  </code></pre>
  
  <p>but it does not compile. I was expecting the line </p>
  
  <pre><code>.flatMap(name -&gt;  IntStream.range(0, name.length())) 
  </code></pre>
  
  <p>to take the strings and convert them to <code>0,1,2,0,1,2,3,0,1,2</code>. What am I misunderstanding? How can I get this sequence of numbers using the output of <code>name -&gt;  IntStream.range(0, name.length())</code>?<br>
  Thank you in advance.</p>