Collection Presentations
Collection Presentations
Objectives
Sets
Lists
Queues
Maps
Retrieving Elements from Collections
Drawbacks of Array
We cannot store different class object into the same array. The
reason is that an array can store one data type of elements
Adding the object at the end of an array is easy. But, inserting and
deleting the elements in the middle of the array is difficult. In this
case, we have to re-arrange all the elements of the array.
Interface Implementation
Set HashSet
List Stack
LinkedList
ArrayList
Vector
Queue LinkedList
Map HashMap
Hashtable---related to properties
file
Set
A set represents a group of elements arranged just like an array. The
set will grow dynamically when the elements are stored into it. A set
will not allow duplicate elements. If we try to pass the same elements
that is already available in the set, then it is not stored into the set.
Lists
Lists are like sets. They store a group of elements. But lists allow
duplicate values to be stored.
Queues
A Queues represents arrangements of elements in FIFO(First In
First Out) order. This means that an element that is stored as a
First element into the queue will be removed first from the queue.
Maps
Maps store elements in the form of key and value pairs. If the key
is provided then its corresponding value can be obtained. Of
courses, the keys should have unique values.
Retrieving Elements from collections
Void remove(): This method removes from the collection the last
element returned by the iterator.
ListIterator Interface
Void remove(): This removes from the list the last element that
was returned by the next() or previous() methods.
Enumeration Interface
This interface is useful to retrieve one by one the elements like the
Iterator. It has 2 methods.
HashSet()
HashSet(int capacity)
HashSet(int capacity, float loadfactor)
HashSet Class Methods
Boolean remove(obj): This method removes the element obj from the
HashSet, if it is present. It returns true if the element is removed
successfully otherwise false.
Void clear(): This removes all the elements from the HashSet.
Int size(): This returns the number of elements present in the HashSet.
See 1st Program