Sunday 13 April 2014

containsValue : Search for Value in the Map

boolean containsValue(Object value)
return true if this map maps one or more keys to the specified value.

import java.util.*;

class MapContainsValue{
  public static void main(String args[]){
    Map<Integer, String> studentTable = new TreeMap<> ();
  
  /* Add Data to studentTable */
  studentTable.put(1, "Joel");
  studentTable.put(2, "Veerendra");
  studentTable.put(3, "Jayanth");
  
  System.out.print("Is studentTable contains value Jayanth ");
  System.out.println(studentTable.containsValue("Jayanth"));
  
  System.out.print("Is studentTable contains value Krishna ");
  System.out.println(studentTable.containsValue("Krishna"));
  }
}

Output
Is studentTable contains value Jayanth true
Is studentTable contains value Krishna false


1. throws ClassCastException if the value is of an inappropriate type for
this map

2. throws NullPointerException if the specified value is null and this map does not permit null values
Prevoius                                                 Next                                                 Home

No comments:

Post a Comment