Conor Crowe wrote:Hello,
I am trying to read in from a text file and enter the data into an ArrayList.
When I tokenize the data read in from the file, there seems to be a whitespace read in which causes an array out of bounds exception when the if clause (tokens.length ==3) is not used.
You can see from the output that an array of size 1 is read at the end of file.
Could someone please explain why it does this?
Thank you
output:
Donnie Darko
sci-fi
Gyllenhall, Jake
3
Raiders of the Lost Ark
action
Ford, Harrison
3
2001
sci-fi
??
3
Caddy Shack
comedy
Murray, Bill
3
Star Wars
sci-fi
Ford, Harrison
3
Lost in Translation
comedy
Murray, Bill
3
Patriot Games
action
Ford, Harrison
3
1
[Donnie Darko sci-fi Gyllenhall, Jake
, Raiders of the Lost Ark action Ford, Harrison
, 2001 sci-fi ??
, Caddy Shack comedy Murray, Bill
, Star Wars sci-fi Ford, Harrison
, Lost in Translation comedy Murray, Bill
, Patriot Games action Ford, Harrison
]
Thank you for your sharing.
I think I don't have to go as deep for understanding the topic in the
SCJP study guide.
What I need is how I can implement
[Donnie Darko sci-fi Gyllenhall, Jake
, Raiders of the Lost Ark action Ford, Harrison
, 2001 sci-fi ??
, Caddy Shack comedy Murray, Bill
, Star Wars sci-fi Ford, Harrison
, Lost in Translation comedy Murray, Bill
, Patriot Games action Ford, Harrison
]
I borrowed your code in below class, which worked well. Thank you.