答案 0 :(得分:2)
您可以在for循环中使用它
String s = "012,345AA,89";
String[] output = s.split(",");
System.out.println(output[0]);
System.out.println(output[1]);
答案 1 :(得分:1)
使用:
String str = "1234,AAA,30";
String[] variables = str.split(",");
String first = variables[0];
String second = variables[1];
String third = variables[2];
这应该有用
答案 2 :(得分:1)
如果数组大小未修复,请尝试此操作
String str = "1234,AAA,30";
String[] arr = str.split(",");
Map<Object, Object> map = IntStream.range(0, arr.length).boxed()
.collect(Collectors.toMap(in -> "var" + (in + 1), in -> arr[in], (k, v) -> v, LinkedHashMap::new));
System.out.println(map);
输出
{var1=1234, var2=AAA, var3=30}