I have an array of strings. The user (hopefully) will fill it with {"word", "word", ...} and then some number of doubles/values after that. I need to take all those values after the first two words, parse them to doubles, and add them to a double array. For example, if the String array is {"add", "key", "2", "4", "5", "1"}, my new double array would return {1, 2, 4, 5, 1}. Here's a code snippet, let me know what you can make of it. For reference, getOption() is the method that returns the array of Strings. Thanks!
public double[] getValues(){
double values[] = new double[getOption().length - 2]; //first two values cannot be parsed to double
for (int i = 2; i < getOption().length; i++){
double valueDouble;
valueDouble = Double.parseDouble(getOption()[i].trim());
values[i] = valueDouble;
}
return values;
}
I'm attempting to use the for loop to pull one value (getOption()[i]), parse it to a double, add it to the values array, and restart the loop until the end of the String array (getOption()) is reached.
edit: forgot to mention my issue: it returns nothing and throws an ArrayOutOfBoundsException 1 in a few seconds.