Collection Implementations Flashcards

Collection Implementations (14 cards)

1
Q

Collection Implementations

A

Implementations are the data objects used to store collections, which implement the interfaces described in the Interfaces section.

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

Describes the different kinds of implementations

A

General-purpose implementations

Special-purpose implementations

Concurrent implementations

Wrapper implementation

Convenience implementations

Abstract implementations

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

General-purpose implementations

A

General-purpose implementations are the most commonly used implementations, designed for everyday use. They are summarized in the table titled General-purpose-implementations

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

Special-purpose implementations

A

Special-purpose implementations are designed for use in special situations and display nonstandard performance characteristics, usage restrictions, or behavior.

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

Concurrent implementations

A

Concurrent implementations are designed to support high concurrency, typically at the expense of single-threaded performance. These implementations are part of the java.util.concurrent package.

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

Wrapper implementations

A

Wrapper implementations are used in combination with other types of implementations, often the general-purpose ones, to provide added or restricted functionality.

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

Convenience implementations

A

Convenience implementations are mini-implementations, typically made available via static factory methods, that provide convenient, efficient alternatives to general-purpose implementations for special collections (for example, singleton sets).

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

Abstract implementations

A

Abstract implementations are skeletal implementations that facilitate the construction of custom implementations — described later in the Custom Collection Implementations section. An advanced topic, it’s not particularly difficult, but relatively few people will need to do it.

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

General-purpose Implementations

A

Interfaces
Set - HashSet, LinkedHashSet, TreeSet (SortedSet)

List - ArrayList, LinkedList

Queue - LinkedList, PriorityQueue

Deque - ArrayDeque, LinkedList

Map - HashMap, LinkedHashMap, TreeMap(SortedMap)

Hash table Implementations
HashSet
HashMap

Resizable array Implementations
ArrayList
ArrayDeque

Tree Implementations
TreeSet
TreeMap

Linked list Implementations
LinkedList

Hash table + Linked list Implementations
LinkedHashSet
LinkedHashMap

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

general-purpose implementations of the Set, List , and Map interfaces

A

the Java Collections Framework provides several general-purpose implementations of the Set, List , and Map interfaces. In each case, one implementation — HashSet, ArrayList, and HashMap — is clearly the one to use for most applications, all other things being equal. Note that the SortedSet and the SortedMap interfaces do not have rows in the table. Each of those interfaces has one implementation (TreeSet and TreeMap) and is listed in the Set and the Map rows. There are two general-purpose Queue implementations — LinkedList, which is also a List implementation, and PriorityQueue, which is omitted from the table. These two implementations provide very different semantics: LinkedList provides FIFO semantics, while PriorityQueue orders its elements according to their values.

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

general-purpose implementations properties

A

Each of the general-purpose implementations provides all optional operations contained in its interface. All permit null elements, keys, and values. None are synchronized (thread-safe). All have fail-fast iterators, which detect illegal concurrent modification during iteration and fail quickly and cleanly rather than risking arbitrary, nondeterministic behavior at an undetermined time in the future. All are Serializable and all support a public clone method.

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

general-purpose implementations are synchronized

A

The fact that these implementations are unsynchronized represents a break with the past: The legacy collections Vector and Hashtable are synchronized. The present approach was taken because collections are frequently used when the synchronization is of no benefit. Such uses include single-threaded use, read-only use, and use as part of a larger data object that does its own synchronization. In general, it is good API design practice not to make users pay for a feature they don’t use. Furthermore, unnecessary synchronization can result in deadlock under certain circumstances.

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

Collection Wrapper Implementations

A

If you need thread-safe collections, the synchronization wrappers, described in the Wrapper Implementations section, allow any collection to be transformed into a synchronized collection. Thus, synchronization is optional for general-purpose implementations, whereas it is mandatory for legacy implementations. Moreover, the java.util.concurrent package provides concurrent implementations of the BlockingQueue interface, which extends Queue, and of the ConcurrentMap interface, which extends Map. These implementations offer much higher concurrency than mere synchronized implementations.

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

Collection Implementations Note

A

As a rule, you should be thinking about the interfaces, not the implementations. That is why there are no programming examples in this section. For the most part, the choice of implementation affects only performance. The preferred style, as mentioned in the Interfaces section, is to choose an implementation when a Collection is created and to immediately assign the new collection to a variable of the corresponding interface type (or to pass the collection to a method expecting an argument of the interface type). In this way, the program does not become dependent on any added methods in a given implementation, leaving the programmer free to change implementations anytime that it is warranted by performance concerns or behavioral details.

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