Java Reference
In-Depth Information
8.
/** Displays only the words that occur with a given frequency.
@param frequency an integer count of the desired frequency. */
public void
display(
int
frequency)
{
Iterator<String> keyIterator = wordTable.getKeyIterator();
Iterator<Integer> valueIterator = wordTable.getValueIterator();
System.out.println("Words that occur " + frequency + " times:");
boolean
atLeastOneWord =
false
;
while
(keyIterator.hasNext())
{
String word = keyIterator.next();
Integer count = valueIterator.next();
if
(count.equals(frequency))
{
atLeastOneWord =
true
;
System.out.println(word);
}
// end if
}
// end while
if
(atLeastOneWord ==
false
)
System.out.println("(There are none.)");
}
// end display
9.
public
ListWithIteratorInterface<Integer> getLineNumbers(String word)
{
return
wordTable.getValue(word);
}
// end getLineNumbers