9:16 am - Sunday March 26, 2017

Hash table example program using entry set of the values

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 Hash table Program is used for entry set of the values using entry set() method

Example Program


import java.util.Hashtable;

import java.util.Set;

public class HashTableSet {

	public static void main(String[] args) {

		// create has table

		Hashtable htable = new Hashtable();

		// put value into table

		htable.put(1, "Dog");

		htable.put(2, "Cat");

		htable.put(3, "Cow");

		htable.put(4, "Donkey");

		// create a set view

		Set nset = htable.entrySet();

		// display set result

		System.out.println("Set result : " + nset);

	}

}

 

Output

Set result : [4=Donkey, 3=Cow, 2=Cat, 1=Dog]

 

Explanation

public static interface Map.Entry<K,V>

 

A map entry (key-value pair). The Map.entrySet method returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view. These Map.Entry objects are valid only for the duration of the iteration; more formally, the behavior of a map entry is undefined if the backing map has been modified after the entry was returned by the iterator, except through the setValue operation on the map entry.

 

Since:

1.2

 

See Also:

Map.entrySet

BACK

Filed in: Z-A All Java Codes

Comments are closed.