Java Reference
In-Depth Information
and class
TreeSet
for manipulating a sorted collection of unique values. You then learned
about Java's interfaces and classes for manipulating key-value pairs—
Map
,
SortedMap
,
Hashtable
,
HashMap
and
TreeMap
. We discussed the specialized
Properties
class for ma-
nipulating key-value pairs of
String
s that can be stored to a file and retrieved from a file.
Finally, we discussed the
Collections
class's
static
methods for obtaining unmodifiable
and synchronized views of collections. For additional information on the collections
framework, visit
http://docs.oracle.com/javase/7/docs/technotes/guides/col-
lections
. In Chapter 17, Java SE 8 Lambdas and Streams, you'll use Java SE 8's new
functional programming capabilities to simplify collection operations. In Chapter 23,
Concurrency, you'll learn how to improve performance on multi-core systems using Java's
concurrent collections and parallel stream operations.
Summary
Section 16.1 Introduction
• The Java collections framework provides prebuilt data structures and methods to manipulate
them.
Section 16.2 Collections Overview
• A collection is an object that can hold references to other objects.
• The classes and interfaces of the collections framework are in package
java.util
.
Section 16.3 Type-Wrapper Classes
• Type-wrapper classes (e.g.,
Integer
,
Double
,
Boolean
) enable programmers to manipulate prim-
itive-type values as objects (p. 687). Objects of these classes can be used in collections.
Section 16.4 Autoboxing and Auto-Unboxing
• Boxing (p. 687) converts a primitive value to an object of the corresponding type-wrapper class.
Unboxing (p. 687) converts a type-wrapper object to the corresponding primitive value.
• Java performs boxing conversions and unboxing conversions automatically.
Section 16.5 Interface
Collection
and Class
Collections
• Interfaces
Set
and
List
extend
Collection
(p. 686), which contains operations for adding, clear-
ing, comparing and retaining objects in a collection, and method
iterator
(p. 691) to obtain a
collection's
Iterator
(p. 687).
• Class
Collections
(p. 688) provides
static
methods for manipulating collections.
Section 16.6 Lists
•A
List
(p. 694) is an ordered
Collection
that can contain duplicate elements.
• Interface
List
is implemented by classes
ArrayList
,
LinkedList
and
Vector
.
ArrayList
(p. 688)
is a resizable-array implementation.
LinkedList
(p. 688) is a linkedlist implementation of a
List
.
• Java SE 7 supports type inferencing with the
<>
notation in statements that declare and create
generic type variables and objects.
•
Iterator
method
hasNext
(p. 691) determines whether a
Collection
contains another element.
Method
next
returns a reference to the next object in the
Collection
and advances the
Iterator
.
•Method
subList
(p. 694) returns a view into a
List
. Changes made to this view are also made
to the
List
.