entrySet Method
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

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());

entrySet: [One, 1]
entrySet: [Two, 2]
entrySet: [Five, 5]
entrySet: [Four, 4]
entrySet: [Seven, 7]
entrySet: [Six, 6]
entrySet: [Three, 3]
© 2016 Microsoft