Java Reference
In-Depth Information
12 dates.add( new CalendarDate(4, 13)); // Jefferson
13 dates.add( new CalendarDate(3, 16)); // Madison
14 dates.add( new CalendarDate(4, 28)); // Monroe
15
16 System.out.println("birthdays = " + dates);
17 Collections.sort(dates);
18 System.out.println("birthdays = " + dates);
19 }
20 }
This program produces the following output:
birthdays = [2/22, 10/30, 4/13, 3/16, 4/28]
birthdays = [2/22, 3/16, 4/13, 4/28, 10/30]
Notice that the dates appear in increasing calendar order after the call on
Collections.sort .
10.3 Case Study: Vocabulary Comparison
In this section we will use ArrayList s to solve a complex problem. We will develop
a program that will read two different text files and compare their vocabulary. In par-
ticular, we will determine the set of words used in each file and compute the overlap
between them. Researchers in the humanities often perform such comparisons of
vocabulary in selections of text to answer questions like, “Did Christopher Marlowe
actually write Shakespeare's plays?”
As we have done with most of our case studies, we will develop the program in stages:
1. The first version will read the two files and report the unique words in each. We
will use short testing files for this stage.
2. The second version will also compute the overlap between the two files (i.e., the
set of words that appear in both files). We will continue to use short testing files
for this stage.
3. The third version will read from large text files and will perform some analysis of
the results.
Some Efficiency Considerations
Many of the early programs in this topic involved fairly simple computations and
fairly small data sets. As you start writing more complex programs, you'll find that
you have to worry about programs running slowly because they are performing
complex computations or handling large amounts of data. We are going to explore
this in much more detail in Chapter 13, but we need to explore it at least briefly for
 
Search WWH ::




Custom Search