ECM2414 Collection Flashcards

1
Q

What is a collection in Java?

A

A collection is an object that groups multiple elements into a single unit, such as a poker hand, a mail folder, or a telephone directory.

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

What is the difference between Collection and Map in Java?

A

Collection: A group of objects known as elements.
Map: A group of objects where each object maps keys to values.

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

What does the Set interface ensure?

A

A Set contains no duplicate elements, and two sets are equal if they have the same elements, regardless of their internal order.

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

What are the main concrete implementations of the Set interface?

A

HashSet: Fast, no order guarantee.
TreeSet: Ordered, uses a red-black tree.
LinkedHashSet: Maintains insertion order.

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

How does the List interface differ from Set?

A

A List is an ordered collection of elements that may contain duplicates, and two lists are equal if they have the same elements in the same order.

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

What are the main concrete implementations of the List interface?

A

ArrayList: Uses a dynamically resizing array.
LinkedList: Uses a doubly linked list.

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

What is a Queue in Java?

A

A Queue is a collection for processing elements, typically in first-in-first-out (FIFO) order.

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

What methods differentiate Queue operations?

A

Add vs. Offer: add throws an exception if capacity is exceeded, while offer returns false.
Remove vs. Poll: remove throws an exception if empty, while poll returns null.
Element vs. Peek: element throws an exception if empty, while peek returns null.

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

What is a Deque?

A

A Deque (double-ended queue) allows insertions and deletions at both ends.

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

What does the Map interface represent?

A

A Map maps keys to values, with each key mapping to at most one value. It uses two generic type arguments, <K, V>.

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

What are the main concrete implementations of the Map interface?

A

HashMap: Unordered, fast.
TreeMap: Ordered by keys.
LinkedHashMap: Maintains insertion order.

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

What is the purpose of the Iterator interface?

A

It provides methods to traverse and optionally remove elements from a collection, ensuring safe iteration.

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

What is a ListIterator, and how does it extend Iterator?

A

A ListIterator allows bidirectional traversal of a list and additional methods like set() and add() for modifying the list.

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

How does the Java Collections Framework enhance programming?

A

It provides reusable and efficient data structures, supports generics, and eliminates the fixed size and limited functionality of arrays.

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

What does the Collection interface provide?

A

It defines fundamental operations like add(), remove(), size(), clear(), and bulk operations like addAll() and retainAll().

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