Tuesday, 27 January 2015

Java : Collection Framework : LinkedHashMap (Remove)


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

LinkedHashMapExample.java
import java.util.LinkedHashMap;

/*
 * Example of remove(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);


        /*
         * Removes the mapping for the specified key from this map if present.
         * 
         * 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.remove(1);

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

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

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