The following questions are about the code Frequencies.java.
Look at the code and observe the differences between doFreqsA
and doFreqsB from that code.
When the program is run using Melville's Bartleby The Scrivener
with 4,256 unique words it generates the output as shown below (it's not
side by side, but vertical when actually run-- below) doFreqsA
on the left and
doFreqsB on the right. This is just a small part of the complete output.
total # words read: 14353
6 A 6 A
1 According 1 According
1 Accordingly 1 Accordingly
1 Accordingly, 1 Accordingly,
1 Acting 1 Acting
1 Adam 1 Adam
time to complete: 1.859000 time to completed 0.020000
Here's the output from Hamlet with 7,806 unique words
total # words read: 31955
1 &c.' 1 &c.'
1 ''Tis 1 ''Tis
5 'A 5 'A
1 'A-down 1 'A-down
1 'Adieu, 1 'Adieu,
1 'And 1 'And
time to complete: 7.534000 time to completed 0.037000
Here's the output from A Scarlet Letter with 14,124 unique words:
total # words read: 85754
1 1
98 " 98 "
9 "A 9 "A
1 "Adorn 1 "Adorn
1 "Advise 1 "Advise
1 "Ah! 1 "Ah!
2 "Ah, 2 "Ah,
time to complete: 36.026000 time to completed 0.097000
This code pertains to the previous two questions.
The single line below occurs in main
String[] words = s.useDelimiter("\\Z").next().split("\\s+");
We could replace this line with the following lines:
ArrayList list = new ArrayList();
while (s.hasNext()){
list.add(s.next());
}
String[] words = list.toArray(new String[0]);