This Java Example shows how to get clone of the TreeMap object in java.
Get Clone of Java TreeMap Example
This Java Example shows how to get clone of the TreeMap object in java. To get clone of the TreeMap object we use Object clone() method. This method returns a shallow copy of this TreeMap instance.
package devmanuals.com; import java.util.*; public class CloneOfTreeMap { public static void main(String args[]) { TreeMap Tmap = new TreeMap(); Tmap.put(1, "Singh"); Tmap.put(3, "Kumar"); Tmap.put(4, "Kumar"); Tmap.put(2, "Nagar"); Tmap.put(6, "Prakash"); System.out.println("The TreeMap Values are as :" + Tmap); System.out.println("The TreeMap clone are as : " + Tmap.clone()); } }
Output:
The TreeMap Values are as :
{1=Singh, 2=Nagar, 3=Kumar, 4=Kumar, 6=Prakash} The TreeMap clone are as : {1=Singh, 2=Nagar, 3=Kumar, 4=Kumar, 6=Prakash} |
[ 0 ] Comments