001package headfirst.iterator.dinermerger; 002 003public class ArrayIterator implements Iterator { 004 MenuItem[] items; 005 int position = 0; 006 007 public ArrayIterator(MenuItem[] items) { 008 this.items = items; 009 } 010 011 public Object next() { 012 MenuItem menuItem = items[position]; 013 position = position + 1; 014 return menuItem; 015 } 016 017 public boolean hasNext() { 018 if (position >= items.length || items[position] == null) { 019 return false; 020 } else { 021 return true; 022 } 023 } 024}