I am having an issue where when I get the program to print the arrays with the split data in it the arrays are not words. They turn out looking like this:
[[Ljava.lang.String;@4aa298b7, [Ljava.lang.String;@7d4991ad, [Ljava.lang.String;@28d93b30,... [[Ljava.lang.String;@66d3c617, [Ljava.lang.String;@63947c6b, [Ljava.lang.String;@2b193f2d,...
This error seems to be specific to my code. I am using a text file not a manually entered array.
I am not sure what is happening to cause them to print out in this manner. Any advice or corrections are greatly appreciated.
Here is my code currently:
import java.io.FileReader;
import com.opencsv.CSVReader;
import java.util.Arrays;
import java.util.ArrayList;
public class SATVocabPractice {
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
ArrayList words = new ArrayList(); //Word arrays
ArrayList definitions = new ArrayList(); //Definition arrays.
//Build reader instance
//Read data.csv
//Default seperator is comma
//Default quote character is double quote
//Start reading from line number 2 (line numbers start from zero)
CSVReader reader = new CSVReader(new FileReader("C:/Users/Brandon/Documents/NetBeansProjects/SAT Vocab Practice/src/sat/vocab/practice/Words.txt"), '|', '"', 0);
//Read CSV line by line and use the string array as you want
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine != null) {
//Verifying the read data here
System.out.println(Arrays.toString(nextLine));
definitions.add(Arrays.toString(nextLine).split("|"));
words.add(Arrays.toString(nextLine).split("\\|"));
}
}
System.out.println(words); //Print the word list
System.out.println(definitions); //Print the definitions
}
}