@Test public void testIterator() { StringList l = new StringList("a"); Iterator<String> it = l.iterator(); Assert.assertTrue(it.hasNext()); Assert.assertEquals("a", it.next()); Assert.assertFalse(it.hasNext()); l = new StringList("a", "b", "c"); it = l.iterator(); Assert.assertTrue(it.hasNext()); Assert.assertEquals("a", it.next()); Assert.assertTrue(it.hasNext()); Assert.assertEquals("b", it.next()); Assert.assertTrue(it.hasNext()); Assert.assertEquals("c", it.next()); Assert.assertFalse(it.hasNext()); }
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 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 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); }
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 int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
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 int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }