I was confused with basic Java where I was trying to use ArrayList which did not work but once I switched to HashSet ,it worked flawlessly.
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestJava {
    public static void main(String[] args) {
        char p = 'p';
        List<Character>  list = new ArrayList<>();
        list.add(p);
        
        Set<Character> set = new HashSet<>();
        set.add(p);
        
        System.out.println(list.remove(p));
        System.out.println(set.remove(p));
    }
}
In above example , I added a character in list and Set and after I tried to remove same character from list , it failed with IndexOutOfBound Exception whereas Set worked.
Why list is not simply removing character?
 
    