I am trying to split a string of 10 numbers and (possibly) letters up and place them into an array. I know that the best way to do this is by using the .split() function that Java offers. I usually don't have a problem with it. However, I am now having trouble with it in a program I am creating. As seen in the code below, I am trying to split the string at every character. The length of the array should therefore be 10. However, the .split("") function is counting the beginning of the string as blank space. This is causing a problem with the rest of the program as there is no element in that index of the array. How can I stop this from happening?
String input = "123456789x";
String[] inputArr = input.split("");
System.out.println("Length: " + inputArr.length);
for(int i=0;i<inputArr.length;i++){
System.out.println(inputArr[i]);
}
This code produces the following result:
Length: 11
(blank index. Not actually in output, its there so you can see. It would otherwise be a blank space)
1
2
3
4
5
6
7
8
9
x