我想确保我真正理解使用 .toUpperCase 时发生的情况 这是一段运行良好的代码。我只是想知道我的评论是否正确描述了正在发生的事情。
char first = 'j'; //Declare char variable & initialize it's value: j
/* toUpperCase method of the Character Class Wrapper is invoked
* char primitives are autoboxed to Character Objects
* toUpperCase method unboxes the converted Characters to char primitives
*/
char firstUp = Character.toUpperCase(first);
感谢大家提供简单和非常详细的答案。非常感谢。
最佳答案
没有。请参阅http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html 。 toUpperCase
的签名是
public static char toUpperCase(char ch)
换句话说,一个char
进入,一个char
出来。在您的示例中,根本没有发生自动装箱或自动拆箱。
关于java - 使用 char toUpperCase 时实际会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19850261/