10:58 pm - Thursday February 23, 2017

Check whether a key is avilable in Treemap boolean containsKey(Objectkey)

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 tutorial explains how  to Check whether a key is avilable in Treemap using boolean

containsKey() method.It checks the specified key contains the value.

Example

import java.util.TreeMap;
class TreeMapContains
{
public static void main(String[] args)
{
   NavigableMap<Integer, String> treemap = new TreeMap<Integer, String>();
   treemap.put(2, "two");
   treemap.put(1, "one");
   treemap.put(3, "three");
   treemap.put(6, "six");
   treemap.put(5 ," ");
   System.out.println("Value for key 6 exists: "+ treemap.containsKey(6));
   System.out.println("For Key 5,is value  exist :"+treemap.containsValue(" "));
 }
}

Output 

               Value for key 6 exists: true

               For Key 5,is value  exist :true

BACK

Filed in: Java Examples

Comments are closed.