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: 
You can sort the list accordingly using [Comparator.comparing](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html), to move all `0` to last and not to sort the remaining values

```
grades.sort(Comparator.comparing(value -> value == 0 ? 1 /* sort last */ : 0 /* don't sort */));  //[9, 8, 1, 7, 3, 0, 0, 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()));
        }

```