Convert a String to an int Array.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.Arrays; class Main { public static void main(String[] args) { String str = "123, 345, 437, 894"; String[] strArr = str.split(","); int size = strArr.length; int [] arr = new int [size]; for(int i=0; i<size; i++) { arr[i] = Integer.parseInt(strArr[i].trim()); } for (int var : arr) { System.out.printf( "num = %d\n", var); } } } |
Output: