Q:

Re-arrange ArrayList elements

I have n number of list of items, containing name and position. If I delete a row from list, I want to re-arrange the positions of the list. 
For example:
Vijay  01
Dhas   02
Arun   03
prabhu 04

If I delete Dhas from the list, Arun's position should be 02 and prabhu's position should be 03. 
My model class is
public class Model {

    private String name;
    private int position;

    public Model(String name, int position) {
        this.name = name;
        this.position = position;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

}

I tried the following:
 @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {
            holder.imvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    int tempPreviousValue;
                    for(int i = position ; i < mData.size()-1 ; i++){
                        int deletedPosition = mData.get(i).getPosition();
                        tempPreviousValue = mData.get(position+1).getPosition();
                        mData.get(position+1).setPosition(deletedPosition);
                    }
                    mData.remove(position);
                    notifyDataSetChanged();

                }
            }); 
        }

But I am not getting the correct order. Can anyone give some ideas to re-arrange the array?

A:

Maybe something like this:
int positionToDelete = 2;
Model modelToDelete = modelList.get(positionToDelete - 1);
modelList.remove(modelToDelete);
for(int i = positionToDelete - 1; i < modelList.size(); i++){
  Model modelToChange = modelList.get(i);
  modelToChange.setPosition(modelToChange.getPosition() - 1);
}

The list will be this before deleting:
[{name = Vijay, position = 1},
 {name = Dhas, position = 2},
 {name = Arun, position = 3},
 {name = prabhu, position = 4}]

And this after deleting:
[{name = Vijay, position = 1},
 {name = Arun, position = 2},
 {name = prabhu, position = 3}]

Try it online.
Or if you already know the Model you want to delete, the first two lines are this instead:
Model modelToDelete = ...; // Model retrieved from some place
int positionToDelete = modelToDelete.getPosition();

The rest stays the same.

