Chapter11:
java.util package
- Collections:A
collection is simply an object that groups multiple elements into
a single unit.
- Collections are used to store, retrieve
and manipulate data,and to transmit data from one method to another.
- Collections typically represent data
items that form a natural group, like a poker hand(collection of
cards), a mail folder(collection of letters), or a telephone directory(a
collection of name-to-phone number mappings)
- Collections define a set of core interfaces.These
are:
-
Collection
-
Set
-
List
-
SortedSet
-
Map
-
SortedMap
- Collection Interface:The collection interface
is the root of the new collections API Library.This interface defines
the basic functions that all classes must implement.
- A class that implements Collection represents
a group of Objects, known as that class's elements.
- All general purpose classes that implement
collections should have a constructor that takes another collection.
- It has a couple of methods that will
flatten all the elements of data structures into an array.This array
is either one it allocates are one you give it as an argument.
- The JDK doesnot provide any direct implementations
of this interface.There are two interfaces that extend Collection
in different directions-
-
Set
-
List
- Set Interface:A set is a collection that
cannot contain any duplicate elements.
- This interface models the mathematical
set abstraction.
- Set Interface extends Collection Interface.
- A set contains no pair of elements e1
and e2 such that e1.equals(e2),and atmost one null element.
- an example of a set is courses making
up a student's schedule or the processes running on a machine.
- The class HashSet implements the Set
Interface.
- HashSet:This class implements the Set
Interface, backed by a hash table.
- This class maintains a collection of
individual objects and you can do intersection, set difference and
iteration over the collection.The hash table makes this operations
fast.
- This class permits the null element.
- HashSet makes no guarantees as to the
iteration order of the set,in particular,it doesnot guarantee that
the order will remain constant over time.
- TreeSet:This class implements Set interface,
backed by a TreeMap instance.
- TreeSet guarantees that the sorted set
will be in ascending element order,sorted according to the natural
order of the elements,or by the comparator provided at set creation,
depending on which constructor is used.
- List:a List is an ordered collection.
- The user has precise control over where
in the list each element is inserted.
- The user can access the elements by their
integer index and search for elements in the list.
- Unlike sets, lists typically allow duplicate
elements.
- Array List,Vector and linked List are
implementations of List Interface.
- Map Interface:A Map is a object that
maps keys to values.
- A Map cannot contain duplicate keys,
each key can map to utmost one value.
- Map doesnot implement collection interface.
- This interface provides three collection
views, which allow viewing a map's contents as a set of keys,a collection
of values or a set of key value pairs.
- Set and Map collections ensure uniqueness,
List Collections donot ensure uniqueness but are sorted.
- SortedSet:A SortedSet is a set that maintains
its elements in ascending order.
- The SortedSet Interface is used for things
like ward lists and membership rolls.
- The class TreeSet is an implementation
of interface SortedSet.
- SortedMap:A SortedMap is a map that maintains
its mappings in ascending key order.
- It is the Map analogue of SortedSet.
- The SortedMap Interface is used for apps
like dictionaries and telephone directories.
|
Interface
|
class implementation |
| Set |
AbstractSet,HashSet |
| List |
AbstractList,LinkedList,Vector,Array List |
| SortedSet |
TreeSet |
| Map |
AbstactMap,HashMap,HashTable |
| SortedMap |
TreeMap |
take
an exam on this topic here
|
Please
submit your ideas on this topic here
|
|
|
|
Copyrights anilbachi.8m.com
All rights reserved
for queries contact anil_kuchana@yahoo.com
|
|