HashTable V get(Object key) Method Example Program


Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The get(Object key) method is used to get the value to which
 *               the specified key is mapped in this hashtable.
 */

public class HashTableGet {
	public static void main(String args[]) {

		Hashtable<Integer, String> ht1 = new Hashtable<Integer, String>();

		ht1.put(1, "Anand");
		ht1.put(2, "Hari Haran");
		ht1.put(3, "Kamal");
		ht1.put(4, "Karthikeyan");
		ht1.put(5, "Mohan");
		ht1.put(6, "Vinoth");
		ht1.put(7, "Hari Haran");

		System.out.println("Values at key 3 is:" + ht1.get(3));
	}
}

Output

Values at key 3 is:Kamal

Explanation

public V get(Object key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

Specified by:
get in interface Map<K,V>
Specified by:
get in class Dictionary<K,V>
Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped, or null if this map contains no mapping for the key
Throws:
NullPointerException - if the specified key is null


Related Post

Comments


©candidjava.com