Example usage for java.util Dictionary elements

List of usage examples for java.util Dictionary elements

Introduction

In this page you can find the example usage for java.util Dictionary elements.

Prototype

public abstract Enumeration<V> elements();

Source Link

Document

Returns an enumeration of the values in this dictionary.

Usage

From source file:Main.java

public static void main(String[] args) {

    Dictionary d = new Hashtable();

    // add 2 elements
    d.put(1, "Cocoa");
    d.put(4, "from java2s.com" + "Bar");
    System.out.println("1 is " + d.get(1));
    System.out.println("4 is " + d.get(4));

    // generates a series of elements, one at a time
    for (Enumeration e = d.elements(); e.hasMoreElements();) {
        System.out.println(e.nextElement());
    }/*from  w  w  w .j a v a2 s.  c o  m*/
}

From source file:org.openengsb.core.util.DictonaryUtilTest.java

@Test
public void wrapMapToDictionary_shouldWrapMapAsDictionary() throws Exception {
    Map<String, String> testMap = new HashMap<String, String>();
    testMap.put("test", "42");
    testMap.put("foo", "bar");
    Dictionary<String, String> dict = MapAsDictionary.wrap(testMap);
    @SuppressWarnings("unchecked")
    List<String> list = EnumerationUtils.toList(dict.elements());
    assertThat(list, hasItems("42", "bar"));
}