Hi everyone I am currently trying to convert a string to an arrayList in reverse and then remove any trailing zeros eg "001203" converts to (3,0.2,1,0,0) and then (3,0,2,1)
my code is currently
public convert(String nums) {
List = new ArrayList<Integer>(); // create arraylist
for (int i = nums.length(); i >= 0; i--) { //convert to int
int j = Integer.parseInt(digits);
List .add(j);
for (Iterator<Integer> k = List .iterator(); k.hasNext();) { //remove trailing zeros
if (k.next().equals(0)) {
k.remove();
}
}
}
This code currently removes all 0s instead of the trailing zeros. meaning my output is (3,2,1) instead of (3,0,2,1);
any help will be appreciated thanks in advance
breakthe loop3, 0.2?, 1, 0, 0is this a typo?