Add a method called reportSet that accepts a list of Strings as its parameter and returns a new set containing only the
Posted: Fri Apr 29, 2022 6:35 am
Add a method called reportSet that accepts a list of Strings as its parameter and returns a new set containing only the unique words from the list. There are 32553 Unique words in the Mobydick file. Measure the time to add mobydick unique words to the set and compare the time adding them to the ArrayList (For this exercise, feel free to modify the starter main file QuizSet main) // start timer long startTime = System.currentTimeMillis (); // end timer long endTime System.currentTimeMillis ();
import java.io.*; import java.util.*; public class QuizSet { // Add reportset here // DO NOT MODIFY the code below public static void main (String [] args) { try{ //ArrayList ArrayList<String> words = new ArrayList<String>(); Scanner input = new Scanner (new File ("mobydick.txt")); while (input.hasNext()) { words.add(input.next()); } System.out.println (reportset(words).size()); } catch (FileNotFoundException e) { System.out.println (e); } } }
import java.io.*; import java.util.*; public class QuizSet { // Add reportset here // DO NOT MODIFY the code below public static void main (String [] args) { try{ //ArrayList ArrayList<String> words = new ArrayList<String>(); Scanner input = new Scanner (new File ("mobydick.txt")); while (input.hasNext()) { words.add(input.next()); } System.out.println (reportset(words).size()); } catch (FileNotFoundException e) { System.out.println (e); } } }