OrderedProperties extends Properties { @Override public synchronized Enumeration<Object> keys() { return new Enumeration<Object>() { private final Iterator<String> i = propertyNames.iterator(); @Override public boolean hasMoreElements() { return i.hasNext(); } @Override public Object nextElement() { return i.next(); } }; } OrderedProperties(); @Override synchronized Object put(Object key, Object value); @Override Set<String> stringPropertyNames(); @Override Enumeration<?> propertyNames(); @Override synchronized Enumeration<Object> keys(); @Override Set<Object> keySet(); @Override Set<Entry<Object, Object>> entrySet(); @Override synchronized void putAll(Map<?, ?> t); @Override synchronized void clear(); @Override synchronized Object remove(Object key);  }
@Test public void testKeys() { Enumeration<Object> keys = orderedProperties.keys(); assertTrue(keys.hasMoreElements()); assertEquals("key1", keys.nextElement()); assertTrue(keys.hasMoreElements()); assertEquals("key2", keys.nextElement()); }