As I'm attempting to remove an item from a List
by the items respective index value I'm realizing (in a "going nuts" sort of way), that again because of pass by referencing I'm getting unexpected results as a developer not used to that concept (learning to like it but not sure how to work around things like this).
Basically once I remove the first index value that then affects the list I'm removing items from so that the next index I want to remove is wrong. This continues perpetually causing the wrong items to be removed from my list.
List<Integer> null values = new List<>(0,2,4);
for(Integer i : nullValues){
myList.remove(i);
}
What's the trick? How do I avoid this typically, at least in this small example here?