Tuesday, 20 January 2015

Java : Collection Framework : HashMap (Clone)


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

HashMapExample.java
import java.util.HashMap;

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

        HashMap<Integer, String> hashMap = new HashMap<Integer, String>();

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

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

        /*
         * Returns a shallow copy of this HashMap instance: the keys and values
         * themselves are not cloned.
         */
        Object object = hashMap.clone();

        System.out
                .println("Object class name : " + object.getClass().getName());

        HashMap<Integer, String> clonedHashMap = (HashMap<Integer, String>) object;

        System.out.println("Cloned HashMap : " + clonedHashMap);

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

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