Tuesday 27 January 2015

Java : Collection Framework : LinkedHashMap (PutAll)


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

LinkedHashMapExample.java
import java.util.LinkedHashMap;
import java.util.TreeMap;

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

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

        treeMap.put(1, "Apple");
        treeMap.put(3, "Cat");
        treeMap.put(2, "Ball");

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

        LinkedHashMap<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();

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

        linkedHashMap.putAll(treeMap);

        System.out.println("linkedHashMap : " + linkedHashMap);

    }
}
Output
treeMap : {1=Apple, 2=Ball, 3=Cat}

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