In: Computer Science
In an eclipse or blues compatible code, please create a class named Items including the described methods (replace and delete0
Write the following static method:
/** Replaces each occurrence of an oldItem in aList with newItem */
public static void replace(ArrayList<String>aList, String oldItem, String newItem)
Write the following static method:
/**Deletes the first occurrence of target in aList*/
public static void delete(ArrayList<String>aList, String target)
import java.util.ArrayList;
import java.util.List;
public class Item {
/** Replaces each occurrence of an oldItem in aList with newItem */
public static void replace(ArrayList<String> aList, String oldItem, String newItem) {
// finding the indexof old item and putting the new item in the same location
int index = aList.indexOf(oldItem);
while (index != -1) {
aList.set(index, newItem);
index = aList.indexOf(oldItem);
}
}
/** Deletes the first occurrence of target in aList */
public static void delete(ArrayList<String> aList, String target) {
// deleting the target by calling remove()
aList.remove(target);
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME