There is a string data
:
{4,15,26,7}
Comma separator is used to separate digits.
this.points=new ArrayList<Integer>();
for (int i = 0; i < data.length(); i++) {
this.points.add(Character.getNumericValue(data.charAt(i)));
}
How to modify this code to be able to skip comma separators and save only digits in this.points
?
Try this,
String data="{4,15,26,7}";
data=data.substring(1,data.length-1);
String[] digits=data.split(",");
his.points=new ArrayList<Integer>();
for (int i = 0; i < digits.length; i++) {
this.points.add(Integer.parseInt(digits[i]));
}