TreeSet addAll Example

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


TreeSet class addAll example. public boolean addAll(Collection c) Adds all of the elements in the specified collection to this set.

Here is the code

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

public class AddAll {

    public static void main(String args[]) {

        Set set = new HashSet();

        // Add the elements to the set and display it:
        set.add("A");
        set.add("Z");
        set.add("S");
        set.add("B");
        System.out.println("Set =" + set);

        // Add the Collection to the treeset and display it:
        Collection treeset = new TreeSet();
        treeset.addAll(set);
        System.out.println("treeset = " + treeset);

    }
}

Here is the code Output
Set =[A, B, S, Z]
treeset = [A, B, S, Z]

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

HOME | COPYRIGHT | CONTACT US