Get Clone Set from Java TreeSet example

Get Clone Set from Java TreeSet example


Posted in : Java Posted on : November 25, 2010 at 12:57 PM Comments : [ 0 ]

In this example, We will discuss about how to get the Clone of java TreeSet object.

Get Clone Set from Java TreeSet example

In this example, We will discuss about how to get the Clone of java TreeSet object. the clone can be obtained by using clone method of Java TreeSet class. To get the clone we use Object clone()  method. This method returns a shallow copy of this TreeSet instance.

The Example is as follows-

CloneOfTreeSetExample.java

package devmanuals.com;

import java.util.TreeSet;

public class CloneOfTreeSet {
	public static void main(String args[]) {

		TreeSet oTreeSet = new TreeSet();

		oTreeSet.add("C");
		oTreeSet.add("A");
		oTreeSet.add("B");
		oTreeSet.add("E");
		oTreeSet.add("F");
		oTreeSet.add("D");
		System.out.println("The TreeSet elements are: " + oTreeSet);

		System.out.println("The clone of TreeSet is: " + oTreeSet.clone());

	}
}

Output:-

The TreeSet elements are: [A, B, C, D, E, F]

 The clone of TreeSet is: [A, B, C, D, E, F]

Download This Example

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics