Q:

ArrayList failed to remove Character

I am trying to remove one Character in my ArrayList. But I always have to build a object to remove, why cannot I remove like the way I add Character?
List<Character> list = new ArrayList<>();
list.add('z');
list.add('x');
list.add('y');
System.out.println("TEST1: " + list);
Character g = new Character('x');
list.remove(g);
System.out.println("TEST2: " + list);
list.remove('y');

The last line gives me these errors:

TEST1: [z, x, y]
TEST2: [z, y]
java.lang.IndexOutOfBoundsException: Index: 121, Size: 2
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.remove(ArrayList.java:492)

The Java doc here shows:
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#remove-java.lang.Object-
boolean        add(E e)
               Appends the specified element to the end of this list.
boolean        remove(Object o)
               Removes the first occurrence of the specified element from this list, if it is present.

A:

ArrayList has two implemention for remove:

public boolean remove(Object o)
public E remove(int index)

When you call it by:
list.remove(Character)

you are calling
public boolean remove(Object o)

so it can success.
But when you call it by:
list.remove('y');

the char y will be converted to int 121(try this System.out.println((int) 'y');), you are implictly calling
public E remove(121)

thats why you get IndexOutOfBoundsException

