I wanted to know if items can be removed from a list while iterating the list using a for loop. What would be the best way to do this? Here's my code:
public static void adder(List<String> batchNumber) {
for (String num : batchNumber) {
Scanner obj = new Scanner(System.in);
System.out.println("batchnumber you want to remove: ");
String answer = obj.nextLine();
if (num==answer){
batchNumber.remove(num);
}
}
}