Click here to watch in Youtube :
https://www.youtube.com/watch?v=XsobNy3Cazw&list=UUhwKlOVR041tngjerWxVccw
TreeMapExample.java
Output
https://www.youtube.com/watch?v=XsobNy3Cazw&list=UUhwKlOVR041tngjerWxVccw
TreeMapExample.java
import java.util.TreeMap; /* * Example of clone() method. */ public class TreeMapExample { public static void main( String[] args ) { TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>(); treeMap.put(1, "Cat"); treeMap.put(2, "Dog"); treeMap.put(4, "Apple"); treeMap.put(3, "Ball"); System.out.println("treeMap : " + treeMap + "\n"); /* * Returns a shallow copy of this TreeMap instance. (The keys and values * themselves are not cloned.) */ Object object = treeMap.clone(); System.out .println("Object class name : " + object.getClass().getName()); TreeMap<Integer, String> clonedTreeMap = (TreeMap<Integer, String>) object; System.out.println("cloned TreeMap : " + clonedTreeMap); } }
treeMap : {1=Cat, 2=Dog, 3=Ball, 4=Apple} Object class name : java.util.TreeMap cloned TreeMap : {1=Cat, 2=Dog, 3=Ball, 4=Apple}
https://sites.google.com/site/javaee4321/java-collections/TreeMapDemoClone.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment