import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String[] array = {"A", "B", "C", "D", "E"};
int[] indexesToRemove = {1, 3};
array = removeElements(array, indexesToRemove);
System.out.println("Modified Array: " + Arrays.toString(array));
}
public static String[] removeElements(String[] array, int[] indexesToRemove) {
Arrays.sort(indexesToRemove);
for (int i = indexesToRemove.length - 1; i >= 0; i--) {
int index = indexesToRemove[i];
if (index >= 0 && index < array.length) {
array = removeElementAtIndex(array, index);
}
}
return array;
}
public static String[] removeElementAtIndex(String[] array, int index) {
if (index < 0 || index >= array.length) {
return array;
}
String[] newArray = new String[array.length - 1];
int newIndex = 0;
for (int i = 0; i < array.length; i++) {
if (i != index) {
newArray[newIndex] = array[i];
newIndex++;
}
}
return newArray;
}
}