public class Demo {
public void stringToArray(String str) {
int shuzi = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) != ',') {
shuzi++;
}
}
int[] arr = new int[shuzi];
int j = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) != ',') {
arr[j] = Integer.parseInt(str.charAt(i) + "");
j++;
}
}
for (int a : arr) {
System.out.print(a + " ");
}
}
public static void main(String[] args) {
String str = "1,3,5,7,9";
Demo demo = new Demo();
demo.stringToArray(str);
}
}