Get Clone of Java TreeMap Example

Get Clone of Java TreeMap Example


Posted in : Java Posted on : December 3, 2010 at 5:33 PM Comments : [ 0 ]

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}

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics