Java Collections Framework

This assignment is about using the Java Collections Framework to accomplish some basic text-processing tasks.These questions involve choosing the right abstraction (Collection, Set, List, Queue, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them.In all cases, sorted order  refers to the natural sorted order on Strings, as defined by String.compareto(s).
  1. [5 marks] Read the input one line at a time and write each line to the output if it is not a duplicate of some previous input line. Take special care so that a file with a lot of duplicate lines does not use more memory than what is required for the number of unique lines.
  2. [5 marks] Read each of the lines of the input and output them in sorted order. Duplicate lines should be printed only once. Take special care so that a file with a lot of duplicate lines does not use more memory than what is required for the number of unique lines.
  3. [5 marks] Read each of the lines of the input and output them in sorted order. Duplicate lines should be printed the same number of times they occur in the input. Take special care so that a file with a lot of duplicate lines does not use more memory than what is required for the number of unique lines.
  4. [5 marks] Read the first 50 lines of input and then write them out in reverse order. Read the next 50 lines and then write them out in reverse order. Do this until there are no more lines left to read.In other words, your output will start with the 50th line, then the 49th, then the 48th, and so on down to the first line. This will be followed by the 100th line, followed by the 99th, and so on down to the 51st line. And so on.Your code should never have to store more than 50 lines at any given time.
  5. [5 marks] Read the whole input one line at a time. Then output all lines sorted by length, with the shortest lines first. In the case where two lines have the same length, resolve their order using the usual sorted order.
  6. [5 marks] Read the entire input one line at a time and then output the even numbered lines (starting with the first line, line 0) followed by the odd-numbered lines.
  7. [5 marks] Read the input one line at a time. At any point after reading the first 42 lines, if some line is blank (i.e., a string of length 0) then output the line that occured 42 lines prior to that one. For example, if Line 242 is blank, then your program should output line 200. This program should be implemented so that it never stores more than 43 lines of the input at any given time.
  8. [5 marks] Read the entire input one line at a time and randomly permute the lines before outputting it.Just to be clear: You shouldn't modify the contents of any line. Instead, I want the same collection of lines printed, but I would like them printed in a random order.
Powered by