Java Reference
In-Depth Information
Moving Beyond Arrays
The Java class library provides a set of data structures in the java.util package that
gives you more flexibility in organizing and manipulating data.
A solid understanding of data structures and when to employ them will be useful
throughout your Java programming efforts.
Many Java programs that you create rely on some means of storing and manipulating
data within a class. Up to this point, you have used three structures for storing and
retrieving data: variables, String objects, and arrays.
These are just a few of the data classes available in Java. If you don't understand the full
range of data structures, you'll find yourself trying to use arrays or strings when other
options would be more efficient or easier to implement.
Outside primitive data types and strings, arrays are the simplest data structure supported
by Java. An array is a series of data elements of the same primitive type or class. It's
treated as a single object but contains multiple elements that can be accessed indepen-
dently. Arrays are useful whenever you need to store and access related information.
The glaring limitation of arrays is that they can't adjust in size to accommodate greater
or fewer elements. You can't add new elements to an array that's already full. Two
objects you learn about today, linked lists and vectors, do not have this limitation.
Unlike the data structures provided by the java.util package,
arrays are considered such a core component of Java that they
are implemented in the language itself. Therefore, you can use
arrays in Java without importing any packages.
NOTE
Java Structures
The data structures provided by the java.util package perform a wide range of func-
tions. These data structures consist of the Iterator interface, the Map interface, and
classes such as the following:
n
BitSet
n
Vector
n
Stack
n
Hashtable
 
 
Search WWH ::




Custom Search