3:13 pm - Thursday December 17, 4331

Retrieve all Keys from HashMap to Set – Set keySet()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                                     This function returns a  set view of the keys contained in the map.

Example Program


import java.util.HashMap;

import java.util.Set;

public class Key 

{

 public static void main(String args[])

	{

		HashMap hp = new HashMap();

		hp.put("1", "yui");

		hp.put("2", "gth");

		hp.put("3", "qwe");

		Set keyset = hp.keySet();

		System.out.println("The values are:" + keyset);

	}

}

Output

    The values are:[3, 2, 1]

BACK

Filed in: Java Examples

Comments are closed.