概述Java程序如何将诸如“ 1,2,3,4,5”之类的字符串转换为数组({1,2,3,4,5})
从zvzdhk:
String[] array = "1,2,3,4,5".split(",");
然后,解析您的整数:
int[] ints = new int[array.length]; for(int i=0; i<array.length; i++) { try { ints[i] = Integer.parseInt(array[i]); } catch (NumberFormatException nfe) { //Not an integer } }