Monday, 2 March 2015

Java : Collection Framework : Hashtable (ContainsValue)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=HPb_zH2-cH4&list=UUhwKlOVR041tngjerWxVccw

HashtableExample.java
import java.util.Hashtable;

/*
 * Example of containsValue(Object value) method.
 */
public class HashtableExample
{
    public static void main( String[] args )
    {

        Hashtable<String, String> hashtable = new Hashtable<String, String>();

        /*
         * Key = CountryCode,Value = CountryName
         */
        hashtable.put("AF", "AFGHANISTAN");
        hashtable.put("BE", "BELGIUM");
        hashtable.put("US", "UNITED STATES");
        hashtable.put("IN", "INDIA");

        System.out.println("hashtable : " + hashtable + "\n");

        /*
         * Returns true if this hashtable maps one or more keys to this value.
         * 
         * Note that this method is identical in functionality to contains
         * (which predates the Map interface).
         */
        boolean isValueExist = hashtable.containsValue("INDIA");

        System.out.println("isValue 'INDIA' Exist : " + isValueExist);

        isValueExist = hashtable.containsValue("Colombia");

        System.out.println("isValue 'Colombia' Exist : " + isValueExist);

    }
}
Output
hashtable : {IN=INDIA, AF=AFGHANISTAN, BE=BELGIUM, US=UNITED STATES}

isValue 'INDIA' Exist : true
isValue 'Colombia' Exist : false
To Download HashtableDemoContainsValue Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoContainsValue.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment