School Project - runing out of time D:
I need to take a string that has 3 words in it and split each word into a new string. New string will be an array. So for example I read a file and stored it in a two dimensional string array. then I take array[i] i being a number that will change since i'm doing this for each line and 2 is the part that contains the three words. Now i want to separate each word on its own and store it in a new two dimensional array but i just can't get it to work.
Here is sample code thats not working for me.
I have to use String Tokenizers. Where is my logic failing here?
initialArray[i].substring(0, initialCourses[i].indexOf(",")); //<----Line 19
StringTokenizer str = new StringTokenizer(initialArray[i], " ");
isolatedArray[i] = new String[str.countTokens()];
int ctr = 0;
String temp = str.nextToken().trim();
isolatedArrayi][ctr] = temp;
Here is the error:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
I also should probably mention each line has a different number of words. and that the first part where i store the lines into a two D array works fine so you don't have to worry about any of that.