Click here to watch in Youtube :
https://www.youtube.com/watch?v=Gk9OEXpZX28&list=UUhwKlOVR041tngjerWxVccw
HashMapExample.java
Output
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); } }
hashMap : {1=Apple, 2=Ball, 3=Cat} Object class name : java.util.HashMap Cloned HashMap : {1=Apple, 2=Ball, 3=Cat}
https://sites.google.com/site/javaee4321/java-collections/HashMapDemoClone.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment