title: Get next item in list that is not in another list in Java
body: <p>I'm trying to make a function to get the next item in a list that is <strong>not</strong> in another list, while also looping to the beginning of the list when it reaches the end.</p>
  
  <p>Basically what I want to happen is:</p>
  
  <pre><code>String[] list = new String[]{"apple", "banana", "cherry", "donut", "egg", "fish", "grape"};
  List&lt;String&gt; list2 = new ArrayList&lt;String&gt;( Arrays.asList("apple", "cherry", "donut", "fish"));
  int index = 4;
  System.out.println(nextItem());
  System.out.println(nextItem());
  System.out.println(nextItem());
  System.out.println(nextItem());
  System.out.println(nextItem());
  //Returns:
  //egg
  //grape
  //banana
  //egg
  //grape
  </code></pre>
  
  <p>I have tried doing this:</p>
  
  <pre><code>public String nextItem() {
      index++;
      if(index == list.size()) index = 0;
      while(list2.contains(list[index])) {
          index++;
          if(index == list.size()) index = 0;
      }
      return list[index];
  }
  </code></pre>
  
  <p>but that does not work, the index just stays the same.</p>
  
  <p>Is there a better way to do this/something similar to this that I don't know of?</p>