title: Remove All null from ArrayList Using Iterator's remove() method
body: <p>I am new for Java . I was just looking for the Iterator in Collection Framework.
  but now I want to remove all null from ArrayList by using Iterator's remove() method .so tried following code but I am not getting expected output as I want a list without any null values . please explain someone Thank you.</p>
  
  <blockquote>
    <p>here is my code</p>
  </blockquote>
  
  <pre><code>package setinterface;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  
  public class InternalWorkingOfArrayList {
  
      public static void main(String[] args) {
  
          List&lt;String&gt; setOfString = new ArrayList&lt;String&gt;();
          setOfString.add("A");
          setOfString.add("B");
          setOfString.add("C");
          setOfString.add("B");
          setOfString.add(null);
          setOfString.add("A");
          setOfString.add(null);
  
  
          Iterator&lt;String&gt; iterator = setOfString.iterator();
          while (iterator.hasNext()) {
              String string = (String) iterator.next();
              if (null==string) {
                  iterator.remove();
                  break;
              }   
          }
          for (String string1 : setOfString) {
              System.out.println(string1);
          }
      }
  }
  </code></pre>