import java.util.*;
public class demo1
{
public static void main(String args[])
{
TreeMap<Integer,String> treemap=new TreeMap<Integer,String>();
treemap.put(1, "C#");
treemap.put(2, "C++");
treemap.put(3, "Java");
treemap.put(4, "Python");
treemap.put(5, "Perl");
System.out.println(treemap);
if(treemap.containsKey(2))
{
System.out.println("The Tree Map contains the key 2");
}
else
{
System.out.println("The Tree Map does not contain the key 2");
}
if(treemap.containsValue("HTML"))
{
System.out.println("The TreeMap contains this value HTML");
}
else
{
System.out.println("The TreeMap does not contain the value HTML");
}
}
}
Java
Program to search a key and value in a Tree Map.

Written by
View ProfileNikhil Juneja
Passionate software developer and technical contributor at TutorialsLink.
