I'm getting this string in Java:
Respuesta1_10|Respuesta2_50|Respuesta4_90|Respuesta5_33
And I need to build two groups of values with it dynamically, since the amount of values separated by |
is not fixed. The groups of values would be:
- answers
- status
To read them there are no problems, I do it like this:
String str="Respuesta1_10|Respuesta2_50|Respuesta4_90|Respuesta5_33";
String[] splitUno =str.split("\|");
for (int x=0; x<splitUno.length; x++)
{
String splitDos[]=splitUno[x].split("\_");
System.out.println(splitDos[0]);
System.out.println(splitDos[1]+"\n");
}
}
At the exit I have:
Respuesta1
10
Respuesta2
50
Respuesta4
90
Respuesta5
33
But I would like to know if there is any easier way to create two sets of values without having to go through the for
loop.
That is, to pass this:
Respuesta1_10|Respuesta2_50|Respuesta4_90|Respuesta5_33
Something like this:
String[] arrRespuestas = {"Respuesta1", "Respuesta2", "Respuesta3", "Respuesta5"};
int[] arrEstatus = {10, 50, 90, 33};