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

A

E poll()

25
Q

Queue Method,Returns next element or returns null if empty queue

A

E peek()

26
Q

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

A

E pop()

27
Q

Map Implementations

A

Hashmap

Tree Map

28
Q

Map Methods, Removes all keys and values from the map.

A

void clear()

29
Q

Map Methods, Returns whether the map is empty.

A

boolean isEmpty() Returns whether the map is empty.

30
Q

Map Methods, Returns the number of entries (key/value pairs) in the map.

A

int size()

31
Q

Map Methods, Returns the value mapped by key or null if none is mapped.

A

V get(Object key)

32
Q

Map Methods, Adds or replaces key/value pair. Returns previous value or null.

A

V put(K key, V value)

33
Q

Map Methods, Removes and returns value mapped to key. Returns null if none.

A

V remove(Object key)

34
Q

Map Methods, Returns whether key is in map.

A

boolean containsKey(Object key)

35
Q

Map Methods, Returns value is in map.

A

boolean containsValue(Object)

36
Q

Map Methods, Returns set of all keys.

A

Set keySet()

37
Q

Map Methods, Returns Collection of all values.

A

Collection values()

38
Q

Java 8 new Map interface methods

A

merge(), computeIfPresent, computeIfAbsent

39
Q

Map method, combine two maps

A

map.merge(BiFunction)

40
Q

Map method, executes a BiFunction if the key is present

A

Map.computeIfPresent(BiFunction)

41
Q

Map method, executes a Function if the key is not present

A

Map.computeIfAbsent(Function)