Collection
Parent interface of collection framework which implements ‘Iterable’ interface
Defines most common methods applicable for all collection objects
This interface is not implemented by any concrete class
List
Child interface in Collection interface
To be used when duplicate elements are required and insertion order to be preserved
Set
Child interface in Collection interface
Set interface does NOT define any new methods; methods from Collection are used
To be used when duplicate elements are NOT allowed and insertion order is not required
Sorted Set
Child interface of Set interface
Stores elements in a specific sorting order
Duplicates are not allowed
Methods: first, last, headSet, tailSet, subSet, comparator => check TreeSet
Navigable Set
Child interface of Sorted Set interface
Provides various methods for navigation
Is implemented by TreeSet
Methods
floor(e): returns highest elements which is <= e
lower(e): returns highest elements which is < e
ceil(e): returns lowest elements which is >= e
higher(e): returns lowest elements which is > e
pollFirst(): remove & return first element
pollLast(): remove & return last element
descendingSet(): returns NavigableSet in reverse order
Queue
It is child interface of Collection interface
Queue guarantees FIFO (First In First Out) behavior
ArrayList also preserves the insertion order and can be used in place of Queue, but FIFO behavior cannot be guaranteed (due to possibility of adding or reading elements using index at any positions)
Methods
Offer: to add an element in the queue
Poll: to remove element, if queue is empty, returns NULL
Remove: to remove element, if queue is empty, raises NoSuchElementException
Peek: to return an element, if queue is empty, returns NULL
Element : to return an element, if queue is empty, raises NoSuchElementException
Map
NOT a child interface of Collection interface
Stores records as key-value pairs
Duplicate keys not allowed, but duplicate values are allowed
Put method returns ‘object’ which is overwritten (i.e. value which is replaced) by current key, if the current key is not duplicate, then it returns null
Sorted Map
Child interface of Map interface
Stores records in a sorted order of keys
Navigable Map
Child interface of Sorted Map interface
Defines several utility methods for navigation purpose
Is implemented by TreeMap
Methods
floorKey(e): returns highest key which is <= e
lowerKey(e): returns highest key which is < e
ceilingKey(e): returns lowest key which is >= e
higherKey(e): returns lowest key which is > e
pollFirstEntry(): returns & removes first Entry in the Map
pollLastEntry(): : returns & removes last Entry in the Map
descendingMap(): : returns reversed Map
No comments:
Post a Comment