Wednesday 4 March 2015

Java : Collection Framework : Hashtable (Elements)


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

HashtableExample.java
import java.util.Enumeration;
import java.util.Hashtable;

/*
 * Example of elements() 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 an enumeration of the values in this hashtable.
         * 
         * Use the Enumeration methods on the returned object to fetch the
         * elements sequentially.
         */
        Enumeration<String> enumeration = hashtable.elements();

        /*
         * Tests if this enumeration contains more elements.
         */
        while( enumeration.hasMoreElements() )
        {
            /*
             * Returns the next element of this enumeration if this enumeration
             * object has at least one more element to provide.
             */
            String value = enumeration.nextElement();

            System.out.println(value);

        }

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

INDIA
AFGHANISTAN
BELGIUM
UNITED STATES
To Download HashtableDemoElements Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoElements.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