Joomla Vorlagen by Website Hosting

PJ1 - 8th laboratory (Collections)

Use the pl1.lab08.Book class, which has the following methods:

  •     toString - returns the English text of the book "The Old Man and the Sea"
  •     getWords - returns individual words of the text in this book as Collection.

1. Print all words sequentially using: the iterator; foreach construction.

2. Using the iterator, remove all words "the" from the returned collection (ignore capitalization with equalsIgnoreCase)

3. Calculate the average word length, and then print all words with an above-average length.

4. Sort words by length.

5. Print all words from the file without repeating (use Set) and ignore the case (use the toLowerCase method of the String class).

6. Modify the previous task to keep the order of the first occurrence (use LinkedHashSet).

7. Determine word frequencies - use Map (the key will be the word and the value will be the number of repetitions).


1. Modify task 5. so that the words from a Set are returned in order sorted by length (use TreeSet with the comparator from task 4).

2. Return words sorted by frequency. (Put words without repeating in a List that you sort using a comparator that uses Maps from Task 7).