Java Collections Flashcards

1
Q

What is a collection?

A

An object that groups multiple elements into a single unit.
Poker hand: collection of cards
Mail folder: collection of letters.

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

Collection vs Map

A

Collection - a group of objects known as elements
public interface Collection
Map - a group of objects where each object maps keys to values
public interface Map

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

How do you iterate over a collection

A

For-each notation,

need an iterator object if you want to safely remove elements while iterating.

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

What is the Set interface?

A

Extends collection, a set contains no duplicate elements. 2 sets are equal if they contain the same elements even if the containers are different.

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

What is the List interface?

A

A list is an ordered collection of elements that may contain duplicate elements. Two lists are treated equal if they contain the same elements in the same order.

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

Concrete List implementation in Java

A

ArrayList

LinkedList

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

What is a Queue interface?

A

Collection of elements stored for processing first in first out.

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

What is a map interface?

A

2 generic type arguments where keys are mapped to value each key maps to at most one value.

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