public class Test { public static void main(String[] args) { String sampleString = "101,203,405"; String[] stringArray = sampleString.split(","); int[] intArray = new int[stringArray.length]; for (int i = 0; i < stringArray.length; i++) { String numberAsString = stringArray[i]; intArray[i] = Integer.parseInt(numberAsString); } System.out.println("Number of integers: " + intArray.length); System.out.println("The integers are:"); for (int number : intArray) { System.out.println(number); } } }
There should be a single loop to go through each element to perform the conversion
Here is the output of the code:
Number of integers: 3 The integers are: 101 203 405