Tuesday 27 January 2015

Java : Collection Framework : LinkedHashMap (PutReturn)


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

LinkedHashMapExample.java
import java.util.LinkedHashMap;

/*
 * Example of put(K key,V value) method.
 */
public class LinkedHashMapExample
{
    public static void main( String[] args )
    {

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

        /*
         * Associates the specified value with the specified key in this map. If
         * the map previously contained a mapping for the key, the old value is
         * replaced.
         * 
         * Returns: the previous value associated with key, or null if there was
         * no mapping for key. (A null return can also indicate that the map
         * previously associated null with key.)
         */
        String value = linkedHashMap.put(1, "Apple");

        System.out.println("Previous value associated with key '1' : " + value);
        System.out.println("linkedHashMap : " + linkedHashMap + "\n");

        value = linkedHashMap.put(1, "Ball");

        System.out.println("Previous value associated with key '1' : " + value);
        System.out.println("linkedHashMap : " + linkedHashMap);


    }
}
Output
Previous value associated with key '1' : null
linkedHashMap : {1=Apple}

Previous value associated with key '1' : Apple
linkedHashMap : {1=Ball}
To Download LinkedHashMapDemoPutReturn Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashMapDemoPutReturn.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