public static void main(String[] args) {
List<String> list = new ArrayList();
list.add("AA");list.add("Aw");list.add("Aw");list.add("AA");
list.add("AA");list.add("A45");list.add("AA");
list.add("Aal");list.add("Af");list.add("An");
System.out.println(list);
for(int i=0;i<list.size();i++){
if(list.get(i).equals("AA")){
list.remove(i);
}
}
System.out.println(list);
}
I am currently attempting to remove all the elements within the ArrayList that have the value of "AA", However, it's only removing some of them and not all. can anyone explain to me what am I doing wrong?
elements within arraylist:
[AA, Aw, Aw, AA, AA, A45, AA, Aal, Af, An]
output after i've attempted to remove all the strings that have the value of "AA".
[Aw, Aw, AA, A45, Aal, Af, An]
why still AA is within the output list?