TreeSet clone Example

TreeSet class clone example. This example shows you how to use clone method.


TreeSet class clone example.public Object clone() Returns a shallow copy of this TreeSet instance. (The elements themselves are not cloned.)

Here is the code

/**
 * @ # Clone.java
 * A class repersenting use to clone method 
 * of TreeSet class in java.util package
 * version 23 May 2008
 * author Rose India 
 */
import java.util.*;

public class Clone {

    public static void main(String[] args) {
        // Create new TreeSet objects:
        TreeSet treeset1 = new TreeSet();
        TreeSet treeset2 = new TreeSet();

        // Create new element objects and add object objects:
        treeset1.add(new Integer(1));
        treeset1.add(new Integer(2));
        treeset1.add(new Integer(3));

        System.out.println("treeset1 = " + treeset1);

        //Create clone and display
        treeset2 = (TreeSettreeset1.clone();
        System.out.println("treeset2 = " + treeset2);


    }
}

Output
 treeset1 = [1, 2, 3]
treeset2 = [1, 2, 3]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US