Collection Interfaces Flashcards

Collection Interfaces (11 cards)

1
Q

Collection Interfaces

A

The core collection interfaces encapsulate different types of collections, which are mentioned below. These interfaces allow collections to be manipulated independently of the details of their representation. Core collection interfaces are the foundation of the Java Collections Framework.

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

Collections are Generic

A

All the core collection interfaces are generic. For example, this is the declaration of the Collection interface.

public interface Collection…

The syntax tells you that the interface is generic. When you declare a Collection instance you can and should specify the type of object contained in the collection. Specifying the type allows the compiler to verify (at compile-time) that the type of object you put into the collection is correct, thus reducing errors at runtime.

To keep the number of core collection interfaces manageable, the Java platform doesn’t provide separate interfaces for each variant of each collection type. (Such variants might include immutable, fixed-size, and append-only.) Instead, the modification operations in each interface are designated optional — a given implementation may elect not to support all operations. If an unsupported operation is invoked, a collection throws an UnsupportedOperationException. Implementations are responsible for documenting which of the optional operations they support

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

Root Collection Interface.

(A Map is not a true Collection).

A
Collection
Set 
List
Queue
Deque
Map

The last two core collection interfaces are merely sorted versions of Set and Map:
SortedSet
SortedMap

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

Collection Interface

A

It is the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired. Some types of collections allow duplicate elements, and others do not. Some are ordered and others are unordered. The Java platform doesn’t provide any direct implementations of this interface but provides implementations of more specific subinterfaces, such as Set and List.

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

Set Interface

A

A collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets, such as the cards comprising a poker hand, the courses making up a student’s schedule, or the processes running on a machine.

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

List Interface

A

an ordered collection (sometimes called a sequence). Lists can contain duplicate elements. The user of a List generally has precise control over where in the list each element is inserted and can access elements by their integer index (position). If you’ve used Vector, you’re familiar with the general flavor of List.

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

Queue Interface

A

a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations.

In a FIFO queue, all new elements are inserted at the tail of the queue.

Queues typically, but do not necessarily, order elements in a FIFO (first-in, first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator or the elements’ natural ordering. Whatever the ordering used, the head of the queue is the element that would be removed by a call to remove or poll. Other kinds of queues may use different placement rules. Every Queue implementation must specify its ordering properties.

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

Deque Interface

A

a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Deque provides additional insertion, extraction, and inspection operations.
Deques can be used both as FIFO (first-in, first-out) and LIFO (last-in, first-out). In a deque all new elements can be inserted, retrieved and removed at both ends.

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

Map Interface

A

an object that maps keys to values. A Map cannot contain duplicate keys; each key can map to at most one value. If you’ve used Hashtable, you’re already familiar with the basics of Map. Also see

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

SortedSet Interface

A

a Set that maintains its elements in ascending order. Several additional operations are provided to take advantage of the ordering. Sorted sets are used for naturally ordered sets, such as word lists and membership rolls.

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

SortedMap Interface

A

a Map that maintains its mappings in ascending key order. This is the Map analog of SortedSet. Sorted maps are used for naturally ordered collections of key/value pairs, such as dictionaries and telephone directories.

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