Tuesday, 27 January 2015

Java : Collection Framework : LinkedHashMap (Get)


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

LinkedHashMapExample.java
import java.util.LinkedHashMap;

/*
 * Example of get(Object key) 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");

        /*
         * Returns the value to which the specified key is mapped, or null if
         * this map contains no mapping for the key.
         * 
         * A return value of null does not necessarily indicate that the map
         * contains no mapping for the key; it's also possible that the map
         * explicitly maps the key to null. The containsKey operation may be
         * used to distinguish these two cases.
         */
        String value = linkedHashMap.get(2);

        System.out.println("value for the Key '2' : " + value);

        value = linkedHashMap.get(10);

        System.out.println("value for the Key '10' : " + value);

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

value for the Key '2' : Ball
value for the Key '10' : null
To Download LinkedHashMapDemoGet Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashMapDemoGet.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