title: How to check if Iterator.next() is == null?
body: <p>How do I check if the next element in the list is null ?</p>
  
  <pre><code>while(it.hasNext()){
  
              System.out.println(it.next()+"\n");
          }
  </code></pre>
  
  <p>this is how I tried, but when the last element is null it prints it as null.</p>
  
  <p>I tried to change it </p>
  
  <pre><code> while(it.hasNext()){
      if(it.next()==null){
      }else             
          System.out.println(it.next()+"\n");
              }
  </code></pre>
  
  <p>but this just makes it worst because some of the elements don't even print!</p>
  
  <p>This is my Iteration method/anonymous class</p>
  
  <pre><code>public Iterator&lt;Filmi&gt; iterator3DFilms ()throws FilmiException{
          if(filmList.isEmpty())
              throw new FilmiException("No Films on the list");
          return new Iterator&lt;Filmi&gt;(){
              private int index=0;
              public boolean hasNext(){
                  return index &lt;filmList.size();
              }
              public Filmi next(){
                  Filmi lb = filmList.get(index++);
  
                  if(lb.is3D()== true)
                      return lb;
                  if(hasNext())
                      return next();
                  return null;
              }
              public void remove(){}
          };
      }
  </code></pre>
  
  <p>The null print only happens at the last element 
  Thank you.</p>