How do i rearrange my firebase database structure when data will delete?

Keywords: java android

Question: 

In my app user can upload their data in form of array like this.

{   
    "0": "...",
    "1": "...",
    "2": "...",
    "3": "...",
    "4": "...",
    "5": "..."
}

But the problem is that whenever user remove data from this the database structure is scattered like this.

{   
    "0": "...",
    "1": "...",
    "3": "...",
    "4": "...",
    "5": "..."
}

Now i want to rearrange the database structure from value 0 to maximum.

    FirebaseDatabase.getInstance().getReference().child("datas").child(CurrentUserId).addValueEventListener(new ValueEventListener() {
                                    @Override
                                    public void onDataChange(@NonNull DataSnapshot dataSnapshot)
                                    {

                                        for (DataSnapshot data:dataSnapshot.getChildren())
                                        {
                                            String link=data.getValue().toString();
                                            if (link.equals(d[i]))
                                            {
                                                String key =data.getKey();
                                                FirebaseDatabase.getInstance().getReference().child("datas").child(CurrentUserId).child(key).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
                                                    @Override
                                                    public void onComplete(@NonNull Task<Void> task)
                                                    {
                                                        if (task.isSuccessful())
                                                        {
                                                            Toast.makeText(mcontext, "data removed successfully", Toast.LENGTH_SHORT).show();
                                                            progressDialog.dismiss();
***// i want rearrange database structure here //***
                                                        }
                                                        else
                                                        {
                                                            Toast.makeText(mcontext, "error "+task.getException().toString(), Toast.LENGTH_SHORT).show();
                                                            progressDialog.dismiss();
                                                        }
                                                    }
                                                });

                                            }
                                        }
                                    }
                                    @Override
                                    public void onCancelled(@NonNull DatabaseError databaseError) {

                                    }
                                });

Answers: