For Java and in reference to this Question how could I save each value in this array to a separate variable?
If string value is:
1234,AAA,30
Variables would be:
var1=1234
var2=AAA
var3=30
For Java and in reference to this Question how could I save each value in this array to a separate variable?
If string value is:
1234,AAA,30
Variables would be:
var1=1234
var2=AAA
var3=30
You can use this in a for loop
String s = "012,345AA,89";
String[] output = s.split(",");
System.out.println(output[0]);
System.out.println(output[1]);
Use:
String str = "1234,AAA,30";
String[] variables = str.split(",");
String first = variables[0];
String second = variables[1];
String third = variables[2];
and that should work
try this if the array size is not fixed
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);
output
{var1=1234, var2=AAA, var3=30}