Question: Let's say I have this List

```
List<Integer> grades = Arrays.asList(9,8,1,0,7,0,0,3);

```

I want to move all zeros to the last indexes .. So I want the output to be something like:

```
9,8,1,7,3,0,0,0

```

I can do that with simple arrays but I still didn't figure out how to do that in ArrayList.

Answer: 
As noted in the comments, you could reuse the same code you have for arrays by using the `List`'s `get` and `set` methods instead of the `[]` operator.

Another "sneaky" approach could be to utilize the fact that sorting keeps the relative positions of two elements that are equivalent, and sort the list with a custom `Comparator` that sorts according to whether or not an item is equal to `0` - all the zeros will moved to the end, and all the other items will keep their relative postions:

```java
grades.sort(Comparator.comparing(i -> i == 0));

```
Thanks guys ..

I managed to do it the same way I did it with simple arrays :

```

 List<Integer> price = Arrays.asList(9,8,1,0,7,0,0,3);

        int count = 0;

        for(int i=0; i<price.size(); i++) {
            if(price.get(i) !=0) {

                price.set(count++, price.get(i));   

            }

        }
             while(count<price.size()) {
                price.set(count++, 0);

             }
            System.out.print(Arrays.toString(price.toArray()));
        }

```