View RSS Feed

Advanced Java

Java Collection Subtypes

Rate this Entry
by , 02-18-2012 at 04:10 PM (1724 Views)
Collection interface subtypes are given below. They all makes the collection interface extended.

1. List
2. Queue
3. SortedSet
4. Set
5. NavigableSet
6. Deque

One of its subtypes shall be used when Collection interface are needed to be used. At Collection interface, implementation is not supported by Java. Just a set of methods are present in it. Specific Collection types are ignored by it.

To operate at a Collection, use this method:
Java Code: This is the code to explain collection types
public class CollectionUtil{
  public static void performSomething(Collection collection) {
    Iterator iterator = collection.iterator();
    while(iterator.hasNext()){
      Object object = iterator.next();
      //do something to object here...
    }
  }
}
//By using subtypes of Collection, this method is called: 
Set  set  = new HashSet();
List list = new ArrayList();

CollectionUtil.performSomething(set);
CollectionUtil.performSomething(list);

Submit "Java Collection Subtypes" to Facebook Submit "Java Collection Subtypes" to Digg Submit "Java Collection Subtypes" to del.icio.us Submit "Java Collection Subtypes" to StumbleUpon Submit "Java Collection Subtypes" to Google

Categories
Collection

Comments