Tuesday, 27 January 2015

Java : Collection Framework : LinkedHashMap (Constructor Accepts Map)


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

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

/*
 * Example of LinkedHashMap(Map<? extends K,? extends V> m) Constructor.
 */
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");

        /*
         * Constructs an insertion-ordered LinkedHashMap instance with the same
         * mappings as the specified map. The LinkedHashMap instance is created
         * with a default load factor (0.75) and an initial capacity sufficient
         * to hold the mappings in the specified map.
         */

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

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

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

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

    Google+ Followers

    Google+ Badge