9:18 am - Thursday February 23, 2017

Convert hashtable keys 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 method returns set view of the keys contained in the map.

Example Program

import java.util.Hashtable;

public class HashtableKeySet

{

	public static void main(String args[])

	{

		Hashtable htable1 = new Hashtable();

		htable1.put(1, "Add");

		htable1.put(2, "Sub");

		htable1.put(3, "Mul");

		htable1.put(4, "Div");

		Set st = htable1.keySet();

		System.out.println("Display result: " + st);

	}

}

Output

       Display result: [4, 3, 2, 1]

BACK

Filed in: Java Examples

Comments are closed.