The collections framework was designed to meet several goals.
- The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hash tables) are highly efficient.
- The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability.
- Extending and/or adapting a collection had to be easy.The Collections Framework provides a well-designed set of interfaces and classes for storing and manipulating groups of data as a single unit called as a collection.
Before diving into the Collections Framework, it helps to understand some of the terminology and set theory involved when working with the framework.
Mathematical Background
In common usage a collection is the same as the intuitive, mathamatical concept of a set. A set is just a group of unique items, meaning that the group contains no duplicates. The Collections Framework in fact includes a
Set interface, and a number of concrete Set classes. But the formal notion of a set predates Java technology by a century, when the British mathematician George Boole defined it in formal logic. Most people learned some set theory in elementary school when introduced to "set intersection" and "set union" through the familiar Venn Diagrams:
Some real-world examples of sets include the following:
- The set of uppercase letters 'A' through 'Z'
- The set of nonnegative integers {0, 1, 2 ...}
- The set of reserved Java programming language keywords {'import', 'class', 'public', 'protected'...}
- A set of people (friends, employees, clients, ...)
- The set of records returned by a database query
- The set of
Componentobjects in aContainer
- The set of all pairs
- The empty set {}
- Sets contains only one instance of each item
- Sets may be finite or infinite
- Sets can define abstract concepts
- The map of IP addresses to domain names (DNS)
- A map from keys to database records
- A dictionary (words mapped to meanings)
- The conversion from base 2 to base 10
- The
- Collection interface is a group of objects,
with duplicates allowed
- Set
- extends Collection but forbids duplicates
- List
- extends Collection also, allows duplicates and
introduces positional indexing
- Map
- extends neither Set nor Collection
Interface
|
Implementation
|
Historical
|
|||
Set
|
HashSet
|
TreeSet
|
|||
List
|
ArrayList
|
LinkedList
|
Vector
Stack |
||
Map
|
HashMap
|
TreeMap
|
Hashtable
Properties |
||
Collection Interface:The
Collection interface is used to represent any group of objects, or elements.- boolean add(Object element)
- boolean remove(Object element)
- int size()
- boolean isEmpty()
- boolean contains(Object element)
- Iterator iterator()
These examples show the basic properties of sets:
Sets are fundamental to logic, mathematics, and computer science, but also practical in everyday applications in business and systems. The idea of a "connection pool" is a set of open connections to a database server. Web servers have to manage sets of clients and connections. File descriptors provide another example of a set in the operating system.
A map is a special kind of set. It is a set of pairs, each pair representing a one-directional "mapping" from one element to another.
Some examples of maps are:
The Collections Framework is made up of a set of interfaces for working with groups of objects. The different interfaces describe the different types of groups
One thing we should note here that Map is not extends from collection, it is just a collection of pair that is KEY-VALUE pair.
In the Collections
Framework, however, the interfaces Map and Collection are distinct with no lineage in
the hierarchy. The reasons for this distinction have to do with the ways
that Set and Map are used in the Java technology
libraries. The typical application of a Map is to provide access to values stored by keys. The set of
collection operations are all there, but you work with a key-value pair,
instead of an isolated element. Map is therefore designed to support the basic operations
of get() and put() which are not required by Set. Moreover, there are methods that
return Set views of Map objects:
Set set = aMap.keySet();
When designing
software with the Collections Framework, it is useful to remember the following
hierarchical relationships of the four basic interfaces of the framework:
the concrete collection classes follow a naming convention, combining
the underlying data structure with the framework interface. The following table
shows the six collection implementations introduced with the Java 2 framework
Vector, Stack, Hashtable and Properties classes are known as Historical Classes as these are presents since Java-1.0 release.
All the historical collection classes are by default Synchronize but all other classes or i can say new classes are unSynchronized classes. We can make new classes as Synchronize by using Synchronize key word.
Here is a list of the
public methods of Collection in Unified Modeling Language
(UML) notation.
The interface
supports basic operations like adding and removing. When you try to remove an
element, only a single instance of the element in the collection is removed, if
present.
The Collection interface also supports query
operations:

No comments:
Post a Comment