I am trying to read from a file and print the average word length for the ArrayList. When I print or get the average of the list was populated with the font and other material from the .txt file.
I have already created a file reader and here is the code for populating the ArrayList from file:
String homedir = System.getProperty("user.home");
System.out.println("homedir = " + homedir);
JFileChooser jfc = new JFileChooser(new File(homedir));
jfc.showOpenDialog(null);
File file = jfc.getSelectedFile();
Scanner scanner = new Scanner(file);
System.out.println("File read = " + file);
ArrayList<String> words = copyWords(scanner);
return words;
the copyWords method
ArrayList<String> words = new ArrayList<String>();
while (scanner.hasNext()){
words.add(scanner.next().toLowerCase());
}
return words;
I understand that I need to convert it via toString() but how would I do that. I tried to do Arrays.toString(words) but that did not work. Would I have to write the copyWords method using toString() when I add the words?
I guess I am just confused about where my @Override needs to go if anywhere. I tried to search but don't understand how to get what I find to solve my problem.