12:53 pm - Thursday July 27, 2017

Check whether the key is available in HashMap boolean containsKey(Object key)

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 function returns true if the map contains  mapping of the given  key.

Example Program


import java.util.HashMap;

public class Hash {

	public static void main(String args[])

	{

		HashMap hp = new HashMap();

		hp.put("1", "abc");

		hp.put("2", "def");

		hp.put("3", "ghi");

		hp.put("4", "jkl");

		System.out.println("Hashmap elements are:" + hp);

		boolean b = hp.containsKey("3");

		System.out.println("Hash table containing the key 3:" + b);

	}

}

Output

    Hashmap elements are:{3=ghi, 2=def, 1=abc, 4=jkl}

    Hash table containing the  key 3:true

BACK

Filed in: Java Examples

Comments are closed.