I have the following code
while(((line = in.readLine()) != null))
{
String[] val = line.split("<>");
courses.put(val[0], val[1]);
and this is the text i’m trying to read
1<>CIS 101-1
2<>CIS 101-2
3<>CIS 231-1
4<>CIS 231-2
5<>CIS 234-1
6<>CIS 234-2
i get an ArrayIndexOutOfBoundsException when trying to run the program at line
courses.put(val[0], val[1]);
can anyone offer any help?
All of those lines should produce an array of length 2.
Make sure you don’t have a blank line in the end of the file.
You could for instance skip lines that doesn’t conform to the pattern by adding something like