Collections Flashcards
Which invocation of the remove(some args) method throws Exception?
Eg.., remove(100). If the list doesnt contains 100 elements, this invocation throws IndexOutOfBoundException
remove(object), if that object doesnt exists, returns false instead of throwing an exception
For which purposes ArrayList is very good?
Lookup of element at constant time.
Adding or removing of element is slower than accessing the element
What is LinkedList?
It implements both List and Queue.
Main benefit of LinkedList?
access, add or remove element from both the beginning and end of the list
Which classes does the Stack extends?
Stack extends Vector
Treeset implement which Set other than Set?
NavigableSet interface
What are the methods that NavigableSet interface provides?
lower(E e), floor(E e), ceiling(E e), higher(E e)
When do we use Queue?
When we want element to be added or removed in specified order
What is special about double-endede Queue?
We can insert/remove elements from both the front and back of the queue.
What is ArrayDeque?
It is a pure double-ended Queue.
It stores its element in resizeable array
The methods that are available in the ArrayDeque and used in stack are?
push, peek, pop
What is HashMap?
HashMap stores the key in hash tables. This means that it uses hashCode() method of keys to retrieve their values more efficiently
Treemap
Stores the Key in sorted tree structure
How to get a set of all keys in a map?
calling keySet()
How to get collection of all values?
values()
Can we call contains on the Map interface?
No, contains is on the Collection interface and cannot be called here
Can TreeSet allow null?
No, Tree Set involves sorting of elements and object cannot be null for sorting purposes
What is interesting about null in TreeMap?
It allows null values, but no null keys
What is to note about null in Arraydeque?
We cannot put null in ArrayDeque. Some method(poll)
return null as value sometimes and we cannot have null in the collection of ArrayDeque
Which Map doesnt allow null keys or values?
Hashtable
What are the collections that does not allows null?
- Hashtable - no null values
- TreeMap - no null Keys
- TreeSet - no null values
- ArrayDeque -no null values