【发布时间】:2016-12-18 21:55:05
【问题描述】:
我有一个字符串,我想用逗号分隔(简单的过程):
String numbers = "1,2,3";
但是,然后我想将拆分字符串的每个元素转换为一个 int,该 int 可以存储在一个用逗号分隔的 int 数组中:
int[][] array = new int [0][];
array[0] = new int[] {1,2,3};
我怎样才能做到这一点?
【问题讨论】:
-
您不需要二维数组。拆分字符串并将其解析为 Integer。
-
我可以在使用 Integer.parseint() 将字符串拆分为整数后对其进行解析,但是我想知道如何创建逗号分隔的整数?
-
@Yehudah 检查我的答案。如果我理解正确的话,我想这就是你要找的东西。
标签: java arrays string split int