Generics and Collections Flashcards

1
Q

When using primitive operands, how does the == operator determine equality?

A

By comparing their underlying values

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

Which phrase describes the compiler replacing all generic parameters with existing types that match the required bounds or Object if the type parameter is unbounded?

A

type erasure

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

Which interface provides a natural order of elements for a Map?

A

SortedMap

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

What is a raw type?

A

A traditional collection that uses Object to store its elements.

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

Which four methods will return the first element in a Deque?

A

pop, poll, peek, remove,

Also removeFirst, pollFirst, peekFirst, element, getFirst

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

Which limitation on instantiation is a direct result of type erasure?

A

Generic parameters cannot be directly instantiated.

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

Which keyword is used in conjunction with the ? character to specify a lower bound for allowable data types?

A

super

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

Which type of collection cannot contain duplicate elements?

A

Set

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

Which conversion between raw and parameterized types will generate an unchecked conversion warning?

A

Conversion from raw type to parameterized type

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

When is the diamond operator used with a constructor to infer a type for a generic parameter?

A

The type is explicitly specified in the variable declaration.

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

Which keyword is used in conjunction with the ? character to specify an upper bound for allowable data types?

A

extends

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

Which interface should be implemented to sort elements in an order other than the default order in collection?

A

Comparator

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

Which keyword applies to either an interface or a superclass when bounding generic parameters?

A

extends

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

Which operator indicates an empty set of type parameters using type inference?

A

Diamond (<>) operator

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

Which conversion does a compiler automatically provide between primitive types and corresponding object wrapper classes?

A

Autoboxing

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

When using reference operands, how does the == operator determine equality?

A

By comparing their object references

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

What is the primary storage and retrieval mechanism for a Map?

A

name/value pairs

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

Which interface should be implemented by objects that can be sorted as elements in a collection?

A

Comparable

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

Which conversion between raw and parameterized types will NOT generate an unchecked conversion warning?

A

Conversion from parameterized type to raw type

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

Which character indicates a wildcard for allowable data types?

A

?

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

What collection classes implement Deque and can be used to represent a LIFO stack?

A

ArrayDeque, ConcurrentLinkedDeque, LinkedBlockingDeque, LinkedList
These are preferred over Stack

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

LIFO

A

Last In First Out

23
Q

ArrayDeque

A

Implements Deque and Queue

Resizable-array implementation of the Deque interface. Not thread safe.

24
Q

ConcurrentLinkedDeque

A

Implements Deque and Queue

An unbounded concurrent deque based on linked nodes. Null elements not allowed

25
Q

LinkedBlockingDeque

A

Implements BlockingQueue, Deque, Queue

An optionally-bounded blocking deque based on linked nodes.

26
Q

LinkedList

A

Implements Deque, Queue
Doubly-linked list implementation of the List and Deque interfaces. Implements all optional list operations, and permits all elements (including null).

27
Q

The add Queue method is equivalent to what Deque method?

A

addLast

28
Q

The offer Queue method is equivalent to what Deque method?

A

offerLast

29
Q

The remove Queue method is equivalent to what Deque method?

A

removeFirst

30
Q

The poll Queue method is equivalent to what Deque method?

A

pollFirst

31
Q

The element Queue method is equivalent to what Deque method?

A

getFirst

32
Q

The peek Queue method is equivalent to what Deque method?

A

peekFirst

33
Q

The push Stack method is equivalent to what Deque method?

A

addFirst

34
Q

The pop Stack method is equivalent to what Deque method?

A

removeFirst

35
Q

The peek Stack method is equivalent to what Deque method?

A

peekFirst

36
Q

Which queue and deque methods will throw an exception if an element cannot be added due to capacity restructions?

A

add, addFirst, addLast, push

37
Q

What exception is thrown by a class implementing Queue or Deque if a capacity restruction is violated on an insert?

A

IllegalStateException

38
Q

Which queue and deque methods will return a special value if an element cannot be added due to capacity restructions?

A

offer, offerFirst, offerLast

39
Q

Which blockingQueue methods will block (wait) if an element cannot be added due to capacity restructions?

A

put, putFirst, putLast

40
Q

Which blockingQueue methods will wait for a specified time if an element cannot be added due to capacity restructions?

A

offer, offerFirst, offerLast

If timeout occurs a special value is returned.

41
Q

Which retrieveal queue and deque methods will throw an exception if the queue is empty?

A

remove, removeFirst, removeLast

42
Q

Which retrieveal queue and deque methods will return a special value if the queue is empty?

A

poll, pollFirst, pollLast

43
Q

Which retrieveal queue and deque methods will wait for a value if the queue is empty?

A

take, takeFirst, takeLast

44
Q

Which inspection queue and deque methods will throw an exception if the queue is empty?

A

element, getFirst, getLast

45
Q

Which inspection queue and deque methods will return a special value if the queue is empty?

A

peek, peekFirst, peekLast

46
Q

Name two classes that implement the Map interface?

A

AbstractMap, ConcurrentHashMap, ConcurrentSkipListMap, HashMap, Hashtable, IdentityHashMap, LinkedHashMap, TreeMap, WeakHashMap

47
Q

Name two subinterfaces that extend the Map interfaces

A

ConcurrentMap, ConcurrentNavigableMap, NavigableMap

48
Q

Can the list return from Arrays.asList can be modified?

A

No, The Arrays.asList method returns a List object that is backed by a fixed-length array. You cannot modify the List object returned by this array, so calling methods such as add() or remove() will result in throwing an UnsupportedOperationException.

49
Q

What is a SkipList

A

A skip list is a data structure that allows fast search within an ordered sequence of elements. Fast search is made possible by maintaining a linked hierarchy of subsequences, each skipping over fewer elements.

50
Q

What java collection or “collection like” classes implement a skiplist structure?

A

ConcurrentSkipListSet, ConcurrentSkipListMap

51
Q

What is the difference between a LinkedListDeque and ArrayDeque?

A

LinkedList is maintaining nodes where the array is just using one big array. Array is better provided that it is sized correctly otherwise it has to double the size and copy if the number of elements exceeds the array size.

52
Q

For TreeSet, if an iterator is created and the TreeSet ojbect is modified (insert/remove) what happens with the iterator is used?

A

The iterators returned by this class’s iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator’s own remove method, the iterator will throw a ConcurrentModificationException.

53
Q

What is fail safe

A

TBD