Discuss / Java / 1

why my result is changed?

 Hello

HELLO

is it correct?

Yes. Because s =s.toUpperCase(),这个语句把s又指向了变为大写的字符串。如果你写成:

String s = "Hello";
String s1 = s.toUpperCase();
System.out.println(s); //Hello 没变
System.out.println(s1); //HELLO 变为大写

吴颖超c

#3 Created at ... [Delete] [Delete and Lock User]

谢哥们


  • 1

Reply