Collections Flashcards Preview

Java8 > Collections > Flashcards

Flashcards in Collections Deck (21)
Loading flashcards...
1

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

2

For which purposes ArrayList is very good?

Lookup of element at constant time.
Adding or removing of element is slower than accessing the element

3

What is LinkedList?

It implements both List and Queue.

4

Main benefit of LinkedList?

access, add or remove element from both the beginning and end of the list

5

Which classes does the Stack extends?

Stack extends Vector

6

Treeset implement which Set other than Set?

NavigableSet interface

7

What are the methods that NavigableSet interface provides?

lower(E e), floor(E e), ceiling(E e), higher(E e)

8

When do we use Queue?

When we want element to be added or removed in specified order

9

What is special about double-endede Queue?

We can insert/remove elements from both the front and back of the queue.

10

What is ArrayDeque?

It is a pure double-ended Queue.
It stores its element in resizeable array

11

The methods that are available in the ArrayDeque and used in stack are?

push, peek, pop

12

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

13

Treemap

Stores the Key in sorted tree structure

14

How to get a set of all keys in a map?

calling keySet()

15

How to get collection of all values?

values()

16

Can we call contains on the Map interface?

No, contains is on the Collection interface and cannot be called here

17

Can TreeSet allow null?

No, Tree Set involves sorting of elements and object cannot be null for sorting purposes

18

What is interesting about null in TreeMap?

It allows null values, but no null keys

19

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

20

Which Map doesnt allow null keys or values?

Hashtable

21

What are the collections that does not allows null?

1. Hashtable - no null values
2. TreeMap - no null Keys
3. TreeSet - no null values
4. ArrayDeque -no null values