Reading in a basic csv file, the first line,(csv), is "abacus,,,,,,,, trust,,". Trying to take out the commas and add the two words to some sort of list or array. The issue starts when I try to reference the first word on the line trie.search("abacus"). Still very new to coding but this one has me stuck.
try {
while ((csv = br.readLine()) != null) {
String[] words = csv.split(",");
System.out.println(csv);
if (words.length == 2) {
String word = words[0].trim();
int code = 0;
trie.insert(word, code);
}
}
} catch(FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(trie.search("abacus"));
I tried inserting the word in several different ways within the word parameter but each time it does not work unless I type "abacus" as the parameter.
In your code, you have the following if-conditional.
Your split method call is going to return 9 elements.
I believe what you are intending to use is a ",+", as you're split parameter.
The split parameter is evaluated as a regular expression pattern.
Which, in this case, a plus character is going to assimilate 1 or more of the character which precedes it.
For example, here are the array elements when a single comma is used.
And, here are the elements when a ",+" is used.