title: How to implement Filtering Iterator in Java?
body: <p>I have created an array (tab[]) of objects and now I need to filter and print via one of their fields (ex. print if ob.a&gt;1 ). I created an Iterator interface, ArrayIterator that goes through all entries on list and Predicate interface. This is constructor of my FilteringIterator:</p>
  <pre><code>private final Iterator iterf;
  private final Predicate pred; 
  public FilteringIterator(ArrayIterator i, Predicate predykat) 
  { 
      iterf=i;
      pred=predykat;
      iterf.first();
  } 
  </code></pre>
  <p>Method that prints every entry using my &quot;basic&quot; iterator looks like this:</p>
  <pre><code>  public void printlist()
  {
      ArrayIterator itab =new ArrayIterator(lista);
      for(itab.first();!itab.isDone(); itab.next())
      {
          Student stud=(Student)itab.current();
          stud.show();
      }
  }
  </code></pre>
  <p>I also have a class that implements Predicate interface:</p>
  <pre><code>public interface Predicate
  
   {
        public boolean accept(Object ob); 
   }
  </code></pre>
  <p>How to use my FilteringIterator, when it requires Predicate, and I cannot create such object, as it's an interface?</p>