Java中的toUpperCase不起作用 [英] toUpperCase in Java does not work
本文介绍了Java中的toUpperCase不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串:
String c = "IceCream";
如果我使用toUpperCase()
函数,则它将返回相同的字符串,但我想获取"ICECREAM"
.
If I use toUpperCase()
function then it returns the same string, but I want to get "ICECREAM"
.
问题出在哪里?
推荐答案
代码
String c = "IceCream";
String upper = c.toUpperCase();
System.out.println(upper);
正确打印"ICECREAM".但是,原始字符串c不变. Java中的字符串是不可变的,因此对该字符串的所有操作都会返回一个新副本.
correctly prints "ICECREAM". However, the original string c isn't changed. Strings in Java are immutable so all operations on the string return a new copy.
这篇关于Java中的toUpperCase不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文