Friday 30 January 2015

Java : Collection Framework : TreeMap (PutAll)


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

TreeMapExample.java
import java.util.HashMap;
import java.util.TreeMap;

/*
 * Example of putAll(Map<? extends K,? extends V> map) method.
 */
public class TreeMapExample
{
    public static void main( String[] args )
    {

        HashMap<Integer, String> hashMap = new HashMap<Integer, String>();

        hashMap.put(1, "Cat");
        hashMap.put(2, "Dog");
        hashMap.put(4, "Apple");
        hashMap.put(3, "Ball");

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

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

        /*
         * Copies all of the mappings from the specified map to this map. These
         * mappings replace any mappings that this map had for any of the keys
         * currently in the specified map.
         */
        treeMap.putAll(hashMap);

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

    }
}
Output
hashMap : {1=Cat, 2=Dog, 3=Ball, 4=Apple}

treeMap : {1=Cat, 2=Dog, 3=Ball, 4=Apple}
To Download TreeMapDemoPutAll Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeMapDemoPutAll.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