Tuesday, 3 March 2015

Java : Collection Framework : Hashtable (Constructor Accepts Map)


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

HashtableExample.java
import java.util.Hashtable;
import java.util.TreeMap;

/*
 * Example of Hashtable(Map<? extends K,? extends V> t) Constructor.
 */
public class HashtableExample
{
    public static void main( String[] args )
    {

        TreeMap<String, String> treeMap = new TreeMap<String, String>();

        treeMap.put("AF", "AFGHANISTAN");
        treeMap.put("BE", "BELGIUM");
        treeMap.put("US", "UNITED STATES");
        treeMap.put("IN", "INDIA");

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

        /*
         * Constructs a new hashtable with the same mappings as the given Map.
         * The hashtable is created with an initial capacity sufficient to hold
         * the mappings in the given Map and a default load factor (0.75).
         */
        Hashtable<String, String> hashtable = new Hashtable<String, String>(
                treeMap);

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

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

hashtable : {IN=INDIA, AF=AFGHANISTAN, BE=BELGIUM, US=UNITED STATES}
To Download HashtableDemoConsAcceptsMap Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoConsAcceptsMap.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