Java Reference
In-Depth Information
// Add lots of elements to the list...
l . add ( source . getDate ());
l . add ( source . getDate ());
l . add ( source . getDate ());
int
int i = 0 ;
Iterator it = l . iterator ();
// Process the data structure using an iterator.
// This part of the code does not know or care
// if the data is an an array, a List, a Vector, or whatever.
while
while ( it . hasNext ()) {
Object o = it . next ();
System . out . println ( "Element " + i ++ + " = " + o );
}
}
}
To demystify the Iterator and show that it's actually easy to build, you create your own
Iterator in Rolling Your Own Iterator .
Structuring Data in a Linked List
Problem
Your data isn't suitable for use in an array.
Solution
Write your own data structure(s).
Discussion
Anybody who's taken Computer Science 101 (or any computer science course) should be fa-
miliar with data structuring, such as linked lists, binary trees, and the like. Though this is not
the place to discuss the details of such things, I'll give a brief illustration of the common
linked list. A linked list is commonly used when you have an unpredictably large number of
data items, you wish to allocate just the right amount of storage, and usually want to access
Search WWH ::




Custom Search