Im trying to create a program which takes a list of common words, scans a book and counts the occurance of each word! Everything is going good, but:
public static void main(String[] args) {
try {
LinkedList<String> commonList = new LinkedList<>();
LinkedList<String> wordList = new LinkedList<>();
String book;
String common;
System.out.println(commonList.get(0));
int[] freqList = new int[commonList.size()];
for (int q = 0; q < 10000; q++) {
int freq = Collections.frequency(wordList, commonList.get(q));
freqList[q] = freq;
System.out.println(commonList.get(q) + ": " + freqList[q]);
//Code which simply adds freq (which holds occurance of word) into 2nd column of commonList array!
}
} catch (Exception e) {
System.out.println(e);
}
}
static String commonData(String common, String commonList) {
try {
Scanner sc2 = new Scanner(new File("common_words.txt"));
while (sc2.hasNextLine()) {
common = sc2.nextLine();
for (String d : common.split(" ")) {
commonList.add(d);
}
}
} catch (Exception e) {
System.out.println(e);
}
return commonList;
}
static String bookData(String book, String wordList) {
try {
Scanner sc = new Scanner(new File("alice_in_wonderland_modified.txt"));
while (sc.hasNextLine()) {
book = sc.nextLine();
for (String s : book.split(" ")) {
wordList.add(s);
}
}
} catch (Exception e) {
System.out.println(e);
}
return wordList;
}
}
Within the 2 methods I inserted at the bottom, the word "add" is underlined red with the error "cannot find symbol. Symbol: method add(String) ... "
Does anybody understand why this is happening? Thanks for anything!
EDIT: At 1 point I didn't have any extra methods and had all the code sit in the main method. In order to store the data that needs to be scanned + use a for loop to actually scan the data, I made 2 methods at the bottom of the page (to process and store data). For some reason ".add" is underlined red only when in these methods, and isn't underlined red when in the main method.