且构网

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

字符串中的首字母大写

更新时间:2023-02-14 18:38:08

尝试做:

rackingSystem = rackingSystem.toLowerCase();

而不是:

rackingSystem.toLowerCase(); 

字符串是不可变的,你必须重新分配的结果toLowerCase()

Strings are immutable, you must reassign the result of toLowerCase().

虽然更容易,(只要您的字符串大于长度2):

Easier though, (as long as your String is larger than length 2):

rackingSystem = rackingSystem.substring(0,1).toUpperCase() + rackingSystem.substring(1).toLowerCase();