Collections Flashcards

1
Q

Which invocation of the remove(some args) method throws Exception?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For which purposes ArrayList is very good?

A

Lookup of element at constant time.

Adding or removing of element is slower than accessing the element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is LinkedList?

A

It implements both List and Queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Main benefit of LinkedList?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which classes does the Stack extends?

A

Stack extends Vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Treeset implement which Set other than Set?

A

NavigableSet interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the methods that NavigableSet interface provides?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When do we use Queue?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is special about double-endede Queue?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is ArrayDeque?

A

It is a pure double-ended Queue.

It stores its element in resizeable array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

push, peek, pop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is HashMap?

A

HashMap stores the key in hash tables. This means that it uses hashCode() method of keys to retrieve their values more efficiently

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Treemap

A

Stores the Key in sorted tree structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

calling keySet()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to get collection of all values?

A

values()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can we call contains on the Map interface?

A

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

17
Q

Can TreeSet allow null?

A

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

18
Q

What is interesting about null in TreeMap?

A

It allows null values, but no null keys

19
Q

What is to note about null in Arraydeque?

A

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
Q

Which Map doesnt allow null keys or values?

A

Hashtable

21
Q

What are the collections that does not allows null?

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