Friday 30 January 2015

Java : Collection Framework : LinkedHashMap (EntrySet)


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

LinkedHashMapExample.java
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/*
 * Example of entrySet() method.
 */
public class LinkedHashMapExample
{
    public static void main(String[] args)
    {

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

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

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

        /*
         * A map entry (key-value pair).
         * 
         * Returns a Set view of the mappings contained in this map.
         */
        Set<Map.Entry<Integer, String>> entrySet = linkedHashMap.entrySet();

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

        System.out.println("-----------------------");
        System.out.println("Key" + " | " + "value");
        System.out.println("-----------------------");

        for (Map.Entry<Integer, String> entry : entrySet)
        {
            System.out.println(entry.getKey() + "   | " + entry.getValue());
        }

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

entrySet : [1=Apple, 3=Cat, 2=Ball]

-----------------------
Key | value
-----------------------
1   | Apple
3   | Cat
2   | Ball
To Download LinkedHashMapDemoEntrySet Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashMapDemoEntrySet.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