Collection Flashcards
Give a short description of the interface: Iterable
a class implementing this interface can be used for iterating with a foreach statement
Give a short description of the interface : Collection
Common base interface for classes in the collection hierarchy. When you want to write methods that are very general, you can pass Collection interface.
Most important methods: boolean add(Element elem) void clear() boolean isEmpty() Iterator iterator() boolean remove(Object obj) int size() Object[] toArray()
Give a short description of the interface : List
- Base interface for containers that store a sequence of elements.
- You can access the elements using an index.
Maintains insertion order - Can store duplicates
Give a short description of the interface : Set, SortedSet, NavigableSet
- interfaces for containers that dont allow duplicates
- SortedSet maintains the set elements in a sorted order
- NavigableSet allows searching the set for the closest match
Give a short description of the interface : Map, SortedMap, NavigableMap
interfaces for containers that map keys to values. In sortedMap, the keys are sorted in order
- NavigableMap allows you to search and return the colest match for given search
- Map hierarchy does NOT extend Collection interface
Give a short description of the interface: Queue, Deque
Queue interface is a base interface for containers that hold a sequence of elements for processing.
For ex. the classes implementing Queue can be LIFO or FIFO
* In a deque you can insert or remove elements from both ends
Give a short description of the interface: Iteratir, ListIterator
- You can transverse over the container in the foward direction if a class implements the Iterator interface
- You can traverse in both foward and reverse direction if a class implements the ListIterator interface
Which are the import concrete classes in the Collection Framework?
- ArrayList
- LinkedList
- HashSet
- TreeSet
- HashMap
- TreeMap
- PriorityQueue
Give a brief description of the concrete class ArrayList
- Implemented as a resizable array
- Fast to serach
- Slow to delete/insert
- allow dups
Give a brief description of the concrete class LinkedList
- Doubly linked list data strut
- Fast to insert or delete elements
- slow for searching elements
- can be used when you need stack (LIFO) or Queue(FIFO)
- allow dups
Give a brief description of the concrete class HashSet
- hash table data structure
- does not allow dups
- fast for earching and retrieving elements
- does NOT maintain any order
Give a brief description of the concrete class TreeSet
- red-black tree data structure
- does not allow dup
- store elements in a sorted order
Give a brief description of the concrete class HashMap
- hash-table data structure
- key values pair
- uses hashing for finding a place to search or store a pair
- searching or inserting is very fast
- not store elements in order
Give a brief description of the concrete class TreeMap
- red-black tree data structure
- store elements in a sorted order
Give a brief description of the concrete class PriorityQueue
- heap data structure
- retrieving based on priority
- irrespective of the order in which you insert