Tuesday 3 March 2015

Java : Collection Framework : Hashtable (putAll)


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

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

/*
 * Example of putAll(Map<? extends K,? extends V> t) method.
 */
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");

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

        /*
         * Copies all of the mappings from the specified map to this hashtable.
         * These mappings will replace any mappings that this hashtable had for
         * any of the keys currently in the specified map.
         */

        hashtable.putAll(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 HashtableDemoPutAll Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/HashtableDemoPutAll.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