A collection is sometimes called container, is simply an object that groups a multiple elements into single unit.
- It is used to store, retrieve, manipulate and communicate aggregate data.
The java.util package also contains one of java’s most powerful subsystem:
- The Collection Framework is a sophisticated hierarchy of interfaces and classes that provide technology for managing groups of objects.
It is a unified architecture for representing and manipulating collection.
It contains the followings :
- Interfaces
- Implementation
- Algorithm
Exception Thrown with Collection methods :
- ClassCastException
- NullPointerException
- IllegalArgumentException
- IllegalStateException – if it is full
- Reduce Programming efforts
- Increases programming speed and quality
- Reduce efforts to learn new API’s
- Reduce efforts to design new API’s
Interfaces available in Collection:
- Collection
- List
- Set
- Sorted Set
Collection interface
- It enables u to work with group of objects.
- It is top of collection hierarchy
Collections and Arrays Classes from Object class Hierarchy
The Collection classes
- It implements the list Interface
- It supports the dynamic array that can grow as needed
- It implements the list interface
- It provides the link list data structure
It has some additional methods like :
- addFirst()
- addLast()
- removeFirst()
- removeLast()
- It implements the set interface
- It creates the collection that uses the hash table for storage
- A hashtable stores a information by using a mechanism called Hashing.
- You cant directly index the hashtable
- It provides the implements the set interface that uses a tree for storage
- Objects are stored in sorted ascending order
- Access and retrieval time are quite fast which makes TreeSet an excellent choice when storing large amount of data that must be found quickly
- It maps unique key to value. A key is an object that use to retrieve a value at a later date.
- Given a key to value, you can store the value in a map object
- After the value is stored, you can retrieve it by using its key
The Map classes
- This class uses a hash table to implement the map interface
- To implement hash table it does not add any new methods of its own
- It does not guarantee the order of its elements
- It implements the map interface by using a tree
- It provides an efficient mean of sorting key/value pairs.
- A tree map guarantee that its elements will be sorted in ascending order key
- It implements a dynamic array
- It is similar to array list but with two differences
- Vector is synchronized
- It contain many legacy methods which are not a part of collection like addElement(), removeElements();
Note : The initial size of vector is 10
- It is an abstract class that represent key/value storage and operate much like map
- Given a key & value ,you can store the value in dictionary object
- Although not deprecated, Dictionary is classified as obsolete, because it is fully superseded by Map.
- It is a concrete implementation of dictionary.
- It is similar to hash map but it is synchronized.
- While using a Hash table you specify an object that is used as a key and value that is linked to a key.
- Hash table store a information by using hashing.
- It is subclass of HashTable
- It is used to maintain list of values,in which the key is string and value is also a string
- The property class is used by many other java classes
- represents a persistent set of properties. { store & load methods }
store
public void store(OutputStream out, String comments) throws IOException
load
public void load(InputStream inStream)
//Reads a property list (key and element pairs) from the input stream.
- The functionality of Enumeration interface is duplicated by the Iterator interface. Iterator has a remove() method while Enumeration doesn’t.
- Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects.
- where as using Iterator we can manipulate the objects also like adding and removing the objects.
Recent Comments