Code example for Enumeration

Methods: hasMoreElementsnextElement

0
 
	public void testKeyEnumerator() { 
		NSDictionary<String, String> dict = new NSDictionary<String, String>("value", "key");	
		Enumeration<String> e = dict.keyEnumerator();
		 
		assertTrue(e.hasMoreElements());
		assertEquals("key", e.nextElement());
		assertFalse(e.hasMoreElements());
		try { 
			e.nextElement();
			fail("Expected NoSuchElementException"); 
		} catch (NoSuchElementException ex) {} 
	} 
	 
	public void testObjectEnumerator() { 
		NSDictionary<String, String> dict = new NSDictionary<String, String>("value", "key");	
		Enumeration<String> e = dict.objectEnumerator();
		 
		assertTrue(e.hasMoreElements());
		assertEquals("value", e.nextElement());