Respuesta :
Answer:
public static void removeInRange(ArrayList<Integer> myList, int value, int start, int end){
int count = 0;
int i = start;
while( i < (end-count) ) {
if( myList.get(i) == value ) {
myList.remove(i);
count++;
}
else {
i++;
}
}
}
Explanation:
Create a method removeInRange that has 4 parameters;
- The list that need to be filtered
- The value that need to be removed from a specific range
- The starting index of specific range
- The ending index of specific range
Initialize the count variable with 0 while the i variable with starting index. Run a while loop starting from i until the value of i is less than the ending index take away count.
Inside the while loop, check if the current number is the specific value that needs to be removed. If true remove the element from the list and increment count variable. Otherwise just increment the i variable which is acting as a counter for the loop.
Keep on iterating until all specific elements are removed from the desired range.