Code: Selecteer alles
public static int[] StringToArr(String rij){
int i=0;
int[] rijArr=new int[rij.length()];
int plekRij=0;
while(rij.indexOf(",")>0){
rijArr[i] = Integer.parseInt(rij.substring(plekRij, rij.indexOf(",")));
plekRij=rij.indexOf(",")+1;
rij=rij.replaceFirst(",",".");
i++;
}
rijArr[i]=Integer.parseInt(rij.substring(plekRij, rij.length()));
int[] rijArr2=new int[i+1];
for(int m=0;m<i+1;m++){
rijArr2[m]=rijArr[m];
}
return rijArr2;
}
Input String:
"123,45,6,789"
Output Array:
[123, 45, 6, 789]