title: Generator functions equivalent in Java
body: <p>I would like to implement an <code>Iterator</code> in Java that behaves somewhat like the following generator function in Python:</p>
  
  <pre><code>def iterator(array):
     for x in array:
        if x!= None:
          for y in x:
            if y!= None:
              for z in y:
                if z!= None:
                  yield z
  </code></pre>
  
  <p>x on the java side can be multi-dimensional array or some form of nested collection. I am not sure how this would work. Ideas?</p>