IteratorUtils { public static Iterator<Character> toIterator(final String value) { return new Iterator<Character>() { int index = 0; @Override public boolean hasNext() { return index < value.length(); } @Override public Character next() { return value.charAt(index++); } @Override public void remove() { } }; }  static Iterator<T> limitIterator(final Iterator<T> it, final long limit); static Iterator<Character> toIterator(final String value); static Iterator<Object> toIteratorArray(final Object array); static Iterator<?> toIterator(Map<?, ?> o); static final Iterator<Object> NULL_ITERATOR; }
@Test public void testConcurrentModification() { HashMap<String, String> map = Maps.newHashMap(); map.put("a", "a"); map.put("b", "b"); Iterator<?> iterator = IteratorUtils.toIterator(map); assertTrue(iterator.hasNext()); iterator.next(); assertTrue(iterator.hasNext()); map.clear(); assertTrue(iterator.hasNext()); try { iterator.next(); fail(); } catch (ConcurrentModificationException e) { } }