StringList implements Iterable<String> { public Iterator<String> iterator() { return new Iterator<String>() { private int index; public boolean hasNext() { return index < size(); } public String next() { if (hasNext()) { return getToken(index++); } else { throw new NoSuchElementException(); } } public void remove() { throw new UnsupportedOperationException(); } }; } StringList(String singleToken);  StringList(String... tokens); String getToken(int index); int size(); Iterator<String> iterator(); boolean compareToIgnoreCase(StringList tokens); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testItertor() { StringList l = new StringList("a"); Iterator<String> it = l.iterator(); assertTrue(it.hasNext()); assertEquals("a", it.next()); assertFalse(it.hasNext()); l = new StringList("a", "b", "c"); it = l.iterator(); assertTrue(it.hasNext()); assertEquals("a", it.next()); assertTrue(it.hasNext()); assertEquals("b", it.next()); assertTrue(it.hasNext()); assertEquals("c", it.next()); assertFalse(it.hasNext()); }