In java java.util package is available. It is not default
package in Java which means that you have to write import statement to use the
features available in this pakcgae.
‘java.util’ package contains many utility classes, legacy
classes and mainly collections framework.
The classes which have been introduced since the first
version of Java are called as legacy classes.
The classes which are introduced from Java2 to manage the
collection of elements/objects are collectively known as collection framework
in Java.
Collection framework in Java is very important set of classes
that lets you implement various data structures in java, effectively and
easily.
To store the group of elements of same type you can use
arrays but arrays have following limitations:
ü You need to
define the type of objects at the time declaration of array.
ü You need to
specify the size of array at the time declaration of array which can not be
changed later.
ü Insertion
and deletion of elements in the middle positions of the array is not possible.
ü You can not
manage and access the elements of array effectively and easily.
To solve
these problems and to handle the elements more effectively and easily following
legacy classes are used in java:
i.
Vector: Vector is a legacy class
used to store objects or collections of elements without any key value or name
value. You can collect all the objects in vector directly.
ii.
Stack: Stack is also legacy class
and it is used to stored objects, like vectors only.
iii.
Hashtable: Can be used
to store the objects or collections of objects as key and its corresponding
name value.
iv.
Dictionary: Can be used
to store the objects or collections of objects as key and its corresponding
name value.
v.
Properties: Can be used
to store the objects or collections of objects as key and its corresponding
name value.
vi.
Enumeration: Enumeration is interface defined in java.util package. The
main purpose of using enumeration interface is to access the data stored in
legacy classes one by one.
These legacy
classes or collection framework has following advantages over arrays:
ü You need
not define the size of collection of objects, at the time of declaration. These
legacy classes or collection framework uses the concept of capacity, which
ensures the dynamic management of memory. Default capacity will be 10, if you
are not defining the capacity initially.
ü You need
not to specify the data type of elements for which you are using the legacy
classes or collections.
ü You can
access the elements of legacy classes or collections framework one by one so
modification is easily possible.
0 comments:
Post a Comment