Properties boolean containsKey(Object key) method Example Program


Tests if the specified object is a key in this hashtable.

Program

package com.candidjava;
import java.util.Hashtable;
import java.util.Properties;
/* 
 * @author : Mohan 
 * @description : The containsKey() method is used to test if some key maps into the specified value in this hashtable.
 */
public class PropertiesContainKey {

	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);
		boolean b= ht.containsKey("3");
		System.out.println(b);

	}

}

Output

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

Explanation

public boolean containsKey(Object key)
Tests if the specified object is a key in this hashtable.
Specified by:
containsKey in interface Map<K,V>
Parameters:
key - possible key
Returns:
true if and only if the specified object is a key in this hashtable, as determined by the equals method; false otherwise.
Throws:
NullPointerException - if the key is null
See Also:
contains(Object)


Related Post

Comments


©candidjava.com