工具方法:

 public static void main(String[] args) {
        System.out.println(upperCaseFirst("barer"));
    }

    public static  String upperCaseFirst(String str){
        return upperCase(str.substring(0, 1)) + str.substring(1);
    }


    public static String upperCase(String str) {

        char[] ch = str.toCharArray();
        if (ch[0] >= 'a' && ch[0] <= 'z') {
            ch[0] = (char) (ch[0] - 32);
        }
        return new String(ch);
    }

 

结果是:

【java】将字符串的首字母大写_编程语言