I've an object and It's JSON schema structured goes like this :
{
"ParentList": [
{
"Parrent": "ListItem0",
"ChildListItems": [
1,
2,
3
]
},
{
"Parrent": "ListItem1",
"ChildListItems": [
1,
2,
3,
4,
5
]
}
]
}
I have consumed this data into an object that has an Array list for Parent. Each item of parent has an array list for children.
When user selects a child of any parent.
I swap the selected parent into 0th position and swap the selected child also into 0th position. Say user selected 4th child of second parent.
{
"ParentList": [
{
"Parrent": "ListItem1",
"ChildListItems": [
4,
2,
3,
1,
5
]
},
{
"Parrent": "ListItem0",
"ChildListItems": [
1,
2,
3
]
}
]
}
But I want to keep the original copy uninterrupted post swapping.
To deal with mutability of List I'm creating a new ArrayList with refernce value of actual list as of follow
parentListCopy = new ArrayList<>(actualParentList);
after swapping my actualParentList indexes are not affected.
But index of child array list getting collapsed based on the swap performed to the copyParent's child list.
{
"ParentList": [
{
"Parrent": "ListItem0",
"ChildListItems": [
1,
2,
3
]
},
{
"Parrent": "ListItem1",
"ChildListItems": [
4,
2,
3,
1,
5
]
}
]
}