- #1
richyw
- 180
- 0
Homework Statement
I need to write a program that takes a text file, and looks for how many unique words it has, as well as the number of times they occur in the file.
Homework Equations
None
The Attempt at a Solution
public static void main(String[] args) throws FileNotFoundException {Scanner s = new Scanner(new File("file.txt"));
String[] wordlist = new String[10000];
int[] wordcount = new int[10000];
int i = 0;
do {
String word = s.next();
if (wordlist.equals(null)) {
wordlist = word;
wordcount ++;
} else if (wordlist.equals(word)) {
wordcount ++;
}
i++;
} while (s.hasNext());
}
when I try and do this, it compiles, but when I run it I get an error. how do I get java to check and see if an element of an array is null?