I have a text file and i want to read each word into an ArrayList<Dictionary> but I have to leave commas, dashes, dots etc. This is the code so far for this purpose:
Scanner sc2 = null;
while (sc2.hasNextLine()) {
Scanner s2 = new Scanner(sc2.nextLine());
while (s2.hasNext()) {
String s = s2.next();
String[] tokens = s.split("\\W+");
s = tokens.toString();
Dictionary.add(s);
}
}
The problem is that when I execute the printing code :
for (int i = 0; i < Dictionary.size();i++) {
System.out.println(Dictionary.get(i));
}
I get the following:
[Ljava.lang.String;@ea2f77
[Ljava.lang.String;@ea6137
[Ljava.lang.String;@ea639
Etc. for every word. I belive that the problem is s = tokens.toString(); but i do not know how to fix it.
Thank you!
Arrays.. Everytime i try to use it, importing the library i get errors.import java.util.Arrays;this is the import statement.