且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字符的 ArrayList 中删除一个字符

更新时间:2023-11-17 18:03:58

一个 char 被提升为一个 int,它优先于自动装箱,所以 remove(int) 被调用而不是 remove(Object)你可能已经直观地期待了.

A char is promoted to an int, which takes precedence over autoboxing, so remove(int) is called instead of remove(Object) you may have intuitively expect.

您可以通过自己装箱参数来强制调用正确"的方法:

You can force the "right" method to be called by boxing the argument yourself:

chars.remove(Character.valueOf('a'));