Java Collections Framework

Part of Collections Framework

  • Collection          Collection Subtypes: The following interfaces (collection types) extends the Collection interface:
      1.  List
      2.  Set
      3. SortedSet
      4. NavigableSet
      5. Queue
      6. Deque 
    Example :
    import java.util.*;
    import java.util.Collection;
    public class collectioninterface {
    public static void main(String[] args) {
    Collection collection = new ArrayList();
    System.out.print(" Elements Of the Array List are ");
    System.out.print(collection + ".");
  • Set    

    Set Interface in Java:-

    The Set interface extends the Collection interface. A Set is a Collection that cannot contain duplicate elements. Not only must these elements be unique, but while they are in the set, each element must not be modified. It permits a single element to be null. The Set interface contains only methods inherited from Collection.

    The Collection Framework provides two concrete set implementations:
    1- HashSet
    2- TreeSet.
    The HashSet represents a set backed by a hash table providing constant lookup−time access to unordered elements.
    The TreeSet maintains its elements in an ordered fashion within a balanced tree.
    The Set interface contains only methods inherited from Collection interface, these are shown  given below:
  • add( )
  • clear( )
  • contains( )
  • isEmpty( )
  • iterator( )
  • remove( )
  • size( )
The Example for the Set interface which impliments the TreeSet class ia
import java.util.*;
public class SetDemo {
        public static void main(String[] args) {

                Set st = new TreeSet();


                Iterator itr = st.iterator();

                while (itr.hasNext()) {
                        String str = (String);

                        System.out.println("Name :" + str);


  1. visit


Post a Comment

Popular posts from this blog

Bluetooth Data Transfer Example

DeCompile .apk file on ubuntu 14.04