Collections and Generics Flashcards

1
Q

Enumerate all the Collections

A
  1. List
  2. Set
  3. Queue
  4. Map
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Common collection method looks at how many elements are in the Collection

A

Collection.isEmpty(), Collection.size()

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

Common collection method, provides an easy way to discard all elements of the Collection.

A

Collection.clear()

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

Common collection method, checks if certain value is in the Collection.

A

Collection.contains()

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

List implementations

A
  1. Arraylist
  2. LInkedLIsts
  3. Vector
  4. ArrayDeque
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List method, add elements to end

A

void add(E element)

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

List method, Adds element at index and moves the rest toward the end

A

void add(int index, E element)

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

List method, Returns element at index

A

E get(int index)

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

List method, Returns first matching index or -1 if not found

A

int indexOf(Object o)

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

List method, Returns last matching index or -1 if not found

A

int lastIndexOf(Object o)

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

List method, Removes element at index and moves the rest toward the front

A

void remove(int index)

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

List method, E set(int index, E e) Replaces element at index and returns original

A

E set(int index, E e)

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

Set Interface Implementations

A

HashSet

TreeSet

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

Navigable Set Interface, Returns greatest element that is < e, or null if no such element

A

E lower(E e)

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

Navigable Set Interface, Returns greatest element that is <= e, or null if no such element

A

E floor(E e)

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

Navigable Set Interface, Returns smallest element that is >= e, or null if no such element

A

E ceiling(E e)

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

Navigable Set Interface, Returns smallest element that is > e, or null if no such element

A

E higher(E e)

18
Q

Queue Implementations

A

ArrayDeque

19
Q

Queue Method, Adds an element to the back of the queue and returns true or throws an exception

A

boolean add(E e)

20
Q

Queue Method, Returns next element or throws an exception if empty queue

A

E element()

21
Q

Queue Method, Adds an element to the back of the queue and returns whether successful

A

boolean offer(E e)

22
Q

Queue Method,Removes and returns next element or throws an exception if empty queue

A

E remove()

23
Q

Queue Method,Adds an element to the front of the queue

A

void push(E e)

24
Q

Queue Method,Removes and returns next element or returns null if empty queue

25
Queue Method,Returns next element or returns null if empty queue
E peek()
26
Queue Method, Removes and returns next element or throws an exception if empty queue
E pop()
27
Map Implementations
Hashmap | Tree Map
28
Map Methods, Removes all keys and values from the map.
void clear()
29
Map Methods, Returns whether the map is empty.
boolean isEmpty() Returns whether the map is empty.
30
Map Methods, Returns the number of entries (key/value pairs) in the map.
int size()
31
Map Methods, Returns the value mapped by key or null if none is mapped.
V get(Object key)
32
Map Methods, Adds or replaces key/value pair. Returns previous value or null.
V put(K key, V value)
33
Map Methods, Removes and returns value mapped to key. Returns null if none.
V remove(Object key)
34
Map Methods, Returns whether key is in map.
boolean containsKey(Object key)
35
Map Methods, Returns value is in map.
boolean containsValue(Object)
36
Map Methods, Returns set of all keys.
Set keySet()
37
Map Methods, Returns Collection of all values.
Collection values()
38
Java 8 new Map interface methods
merge(), computeIfPresent, computeIfAbsent
39
Map method, combine two maps
map.merge(BiFunction)
40
Map method, executes a BiFunction if the key is present
Map.computeIfPresent(BiFunction)
41
Map method, executes a Function if the key is not present
Map.computeIfAbsent(Function)