Java Reference
In-Depth Information
A
a: 2
and: 3
application: 2
arithmetic: 1
I
inputs: 1
instruct: 1
introduces: 1
R
result: 1
results: 2
run: 1
J
java: 1
jdk: 1
S
save: 1
screen: 1
show: 1
sum: 1
B
begin: 1
C
calculates: 1
calculations: 1
chapter: 1
chapters: 1
commandline: 1
compares: 1
comparison: 1
compile: 1
computer: 1
D
decisions: 1
demonstrates: 1
display: 1
displays: 2
L
last: 1
later: 1
learn: 1
T
that: 3
the: 7
their: 2
then: 2
this: 2
to: 4
tools: 1
two: 2
M
make: 1
messages: 2
N
numbers: 2
O
obtains: 1
of: 1
on: 1
output: 1
U
use: 2
user: 1
E
example: 1
examples: 1
W
we: 2
with: 1
P
perform: 1
present: 1
program: 1
programming: 1
programs: 2
F
for: 1
from: 1
Y
you'll: 2
H
how: 2
Fig. 17.18 | Output for the program of Fig. 17.17 arranged in three columns.
Summarizing the Occurrences of Each Word in the File
Lines 19-24 summarize contents of the text file "Chapter2Paragraph.txt" (which is lo-
cated in the folder with the example) into a Map<String, Long> in which each String key
is a word in the file and the corresponding Long value is the number of occurrences of that
word. The statement performs the following tasks:
• Line 20 uses Files method lines to create a Stream<String> for reading the
lines of text from a file. Class Files (package java.nio.file ) is one of many
classes throughout the Java APIs that have been enhanced to support Stream s.
• i e 1 s s Stream method map to remove all the punctuation, except apostro-
phes, in the lines of text. The lambda argument represents a Function that in-
vokes String method replaceAll on its String argument. This method receives
two arguments—the first is a regular expression String to match and the second
is a String with which every match is replaced. In the regular expression,
 
Search WWH ::




Custom Search