Properties 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.
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.)

Program

package com.candidjava;
import java.util.Hashtable;
import java.util.Properties;

/* 
 * @author : Mohan 
 * @description : The get(Object key) method is used to get the value to which the specified key is mapped in this hashtable.
 */
public class PropertiesGet {

	public static void main(String[] args) {
		Properties properties = new Properties();
		Hashtable ht = new Hashtable(properties);
		ht.put("1", "hari");
		ht.put("2", "anand");
		ht.put("3", "vinoth");
		ht.put("4", "mohan");
		ht.put("5", "karthick");
		System.out.println(ht);
		System.out.println(ht.get("3"));
	}

}

Output

{5=karthick, 4=mohan, 3=vinoth, 2=anand, 1=hari}
vinoth

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
See Also:
put(Object, Object)


Related Post

Comments


©candidjava.com