Export (0) Print
Expand All

HashMap.entrySet Method

Visual Studio 2005

Creates and populates a Set object with the elements in the HashMap object.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public java.util.Set entrySet();

A Set object containing the elements of the HashMap object.

The following example populates a Set with the contents of a HashMap.

// hashmap_entryset.jsl

import java.util.*;

public class Program
{
    public static void main(String[] args)
    {
        // Create a HashMap with seven entries.
        HashMap hm = new HashMap();
        hm.put("One", "1");
        hm.put("Two", "2");
        hm.put("Three", "3");
        hm.put("Four", "4");
        hm.put("Five", "5");
        hm.put("Six", "6");
        hm.put("Seven", "7");

        // Create a Set with the entries in the HashMap.
        Set set = hm.entrySet();

        // Iterate over the Set to see what it contains.
        Iterator iter = set.iterator();
        while (iter.hasNext())
        {
            Object o = iter.next();
            System.out.println("entrySet: " + o.toString());
        }
    }
}

/*
Output:
entrySet: [One, 1]
entrySet: [Two, 2]
entrySet: [Five, 5]
entrySet: [Four, 4]
entrySet: [Seven, 7]
entrySet: [Six, 6]
entrySet: [Three, 3]
*/

Community Additions

ADD
Show:
© 2014 Microsoft