I am trying to read a string in from a text file, split the string whenever there are spaces, and store each word in an array of strings:
eg. input "Hello i am a sentence"
output [Hello, i, am, a, sentence]
I currently have the following
Scanner sc = null;
try
{
sc = new Scanner(new FileReader(args[0]));
LinkedList<String> list = new LinkedList<String>();
String str = sc.nextLine();
for(String i:str.split(" ")){
list.add(i);
}
String[] arguments = list.toArray(new String[list.size()]);
System.out.println(arguments);
}
catch (FileNotFoundException e) {}
finally
{
if (sc != null) sc.close();
}
But i am unable to convert the list into an array and i get the following output
[Ljava.lang.String;@45ee12a7