I am trying to convert a string of numbers (e.g “34 4 5 6 67 45 34”) into an array of shorts.
I have written the following code :
//Split the string and then build a short array with the values.
String[] tabOfShortString = finalString.split(" ");
int length = tabOfShortString.length;
System.out.println("Length of float string is" + length);
short[] shortsArray = new short[length];
for (int l = 0; l < length; l++) {
//System.out.println("l is currently "+l);
Short res = new Short(tabOfShortString[l]);
System.out.println("Indice Short Value is " + res);
shortsArray[l] = res;
}
The problem is that the finished array (shortsArray) is not accurately capturing my string. Can anyone spot what may be wrong ?
Thank you.
Your solution works for me, this is what I have:
Then I call this:
And the output of qux is:
I do not see a problem?