Code example for ListIterator

Methods: addhasNextnextremoveset

0
		Object c = new Object();
 
		dynamicList.add(a);
 
		try { 
			iter.set(c);
			fail("should have thrown " + IllegalStateException.class);
		} 
		catch (IllegalStateException ex) {
			// expected 
		} 
 
		iter.next();
		iter.set(b);
 
		assertEquals(1, dynamicList.size());
		assertSame(b, dynamicList.get(0));
		assertFalse(iter.hasNext());
 
		iter.set(c);
 
		assertEquals(1, dynamicList.size());
		assertSame(c, dynamicList.get(0));
		assertFalse(iter.hasNext());
 
		iter.add(b);
 
		try { 
			iter.set(c);
			fail("should have thrown " + IllegalStateException.class);
		} 
		catch (IllegalStateException ex) {
			// expected 
		} 
 
		assertTrue(iter.hasNext());
 
		iter.next();
		iter.set(c);
		iter.remove();
 
		try { 
			iter.set(c);
			fail("should have thrown " + IllegalStateException.class);
		} 
		catch (IllegalStateException ex) {
			// expected 
		} 
Experience pair programming with AI  Get Codota for Java