So I am trying to create this loop that can remove a specific character in a given string from an arraylist. The problem is when there are two of the same characters in a row it will miss the second one because when the first is removed the second one is pushed down a spot in the array list. This is what I have so far. Anyone know how to fix this? I am still a beginner at java so any help would be appreciated.
ArrayList<Character> list = new ArrayList();
String string = "BuBBuopB";
for(int i=0;i<string.length();i++)
list.add(string.charAt(i));
System.out.println("BEFORE: " + list);
for(int i=0;i<list.size();i++)
if(list.get(i).equals('B'))
list.remove(i);
System.out.println("AFTER: " + list);
what is printed from this example is AFTER: [u, B, u, o, p] when I want it to be AFTER: [u, u, o, p]