Wednesday, April 1, 2009

Collection-Interface

The 1.2 release of the Java platform includes a new collections framework. A collection is an object that represents a group of objects. A collections framework is a unified architecture for representing and manipulating collections, allowing them to be manipulated independently of the details of their representation. The Collection interface is the root of the collection hierarchy. A Collection represents a group of objects, known as its elements. Some Collection implementations allow duplicate elements and others do not. Some are ordered and others unordered. The JDK doesn't provide any direct implementations of this interface: It provides implementations of more specific subinterfaces like Set and List. This interface is the least common denominator that all collections implement.

Collection is used to pass collections around and manipulate them when maximum generality is desired.Collection frame work define a set classes and interfaces which can be used for representing a group of objects as single entity.In the case of c++ the corresponding collection frame work is known as STL(Standered template library) and collection is known as container.


There are six collection interfaces. The most basic interface is Collection. Three interfaces extend Collection: Set, List, and SortedSet. The other two collection interfaces, Map and SortedMap, do not extend Collection, as they represent mappings rather than true collections. However, these interfaces contain collection-view operations, which allow them to be manipulated as collections.



Collection Interface:
It defines general methods ,which can be used for a group of individual objects.i.e a collection represents a group of individual ibjects.
Note:
Collection is an interface to represent a group of individual objects where as collections is an utility class for defining utility methods like sorting,searching… etc.
Collection Interface Methods:
This Interface defines general methods which can be applied on any collection object.
1.boolean add(Object obj)
2.boolean addAll(collection c)
3.boolean remove(Object o)
4.boolean removeAll(Collection c)
5.void clear()
6.boolean retainAll(Collection c)
removes all the elements in the collection except those present in c.
7.boolean contains(Object o)
8.boolean containsAll(Collection c)
9.boolean isEmpty()
10.int size()
returns the number of objects present in the collection
11.Object[] toArray()
mainly for improving the performance of the system.
12. Iterator iterator()
to return the objects one by one.


The primary advantages of a collections framework are that it:
• Reduces programming effort by providing useful data structures and algorithms so you don't have to write them yourself.
• Increases performance by providing high-performance implementations of useful data structures and algorithms. Because the various implementations of each interface are interchangeable, programs can be easily tuned by switching implementations.
• Provides interoperability between unrelated APIs by establishing a common language to pass collections back and forth.
• Reduces the effort required to learn APIs by eliminating the need to learn multiple ad hoc collection APIs.
• Reduces the effort required to design and implement APIs by eliminating the need to produce ad hoc collections APIs.
• Fosters software reuse by providing a standard interface for collections and algorithms to manipulate them.





1 comments:

Unknown said...

great work....in every post!
thank you!

Post a Comment