Outline how a Java program could convert a string such as “1,2,3,4,5” into an array ({1, 2, 3, 4,5})
Use StringTokenizer which will split string by comma and then put those values/tokens in array of integers.
public static int[] getIntegers(String numbers) {
StringTokenizer st = new StringTokenizer(numbers, ",");
int[] intArr = new int[st.countTokens()];
int i = 0;
while (st.hasMoreElements()) {
intArr[i] = Integer.parseInt((String) st.nextElement());
i++;
}
return intArr;
}