【java工具類1】代碼字符串的首字母小寫java代碼實現(xiàn)字符串首字母小寫String首字母大小寫Char實現(xiàn)首字母大小寫65-90 是A-Z的大寫 97-122 是字母a-z的小寫ASCII碼值

如果感覺有用,點個贊唄.jpg

工具類實現(xiàn)字母表的實現(xiàn)字符串的String的首字母大小寫,代碼參考如下:

/**
 * 功能說明:字符串實現(xiàn)首字母的大小寫
 *
 * @date 2020年12月16日
 * @author 君子志邦
 * @email 
 * 
 */
public class MainTest {
 
    
    /**
     * 將首字母小寫
     *
     * @param str
     * @return
     */
    private static String lowerFirstChar(String str) {
        char[] chars = str.toCharArray();
        chars[0] += 32;
        return String.valueOf(chars);
    }
 
    /****
     * 將首字母大寫方法
     * @param str
     * @return
     */
    private static String LargerFirstChar(String str) {
        char[] chars = str.toCharArray();
        chars[0] -= 32;
        if(chars[0]>97){
 
        }
        return String.valueOf(chars);
    }
 
    public static void main(String[] args) {
        System.out.println("--首字母小寫-" + lowerFirstChar("MyObject"));
        System.out.println("--首字母大寫-" + LargerFirstChar("myObject"));
    }

測試運行結果:

--首字母小寫-myObject
--首字母大寫-MyObject

主要是是因為碼值有對應的關系

65-90 是A-Z的大寫 97-122 是字母a-z的小寫 ASCII碼值

/**
     * 65-90  是A-Z的大寫   97-122 是字母a-z的小寫 ASCII碼值
     * @param args
     */
    public static void main(String[] args) {
        int a=65;
        char b='A';
        int i=0;
        for(;i<58;i++)
        {
            System.out.printf("ASCII 對應的數(shù)字 %d <----> %c ",a+i,b+i);
            if(i%10==4||i%10==9){
                System.out.println();
            }
        }
    }

詳細的轉(zhuǎn)換對應關系是:

ASCII 對應的數(shù)字 65 <----> A ASCII 對應的數(shù)字 66 <----> B ASCII 對應的數(shù)字 67 <----> C ASCII 對應的數(shù)字 68 <----> D ASCII 對應的數(shù)字 69 <----> E
ASCII 對應的數(shù)字 70 <----> F ASCII 對應的數(shù)字 71 <----> G ASCII 對應的數(shù)字 72 <----> H ASCII 對應的數(shù)字 73 <----> I ASCII 對應的數(shù)字 74 <----> J
ASCII 對應的數(shù)字 75 <----> K ASCII 對應的數(shù)字 76 <----> L ASCII 對應的數(shù)字 77 <----> M ASCII 對應的數(shù)字 78 <----> N ASCII 對應的數(shù)字 79 <----> O
ASCII 對應的數(shù)字 80 <----> P ASCII 對應的數(shù)字 81 <----> Q ASCII 對應的數(shù)字 82 <----> R ASCII 對應的數(shù)字 83 <----> S ASCII 對應的數(shù)字 84 <----> T
ASCII 對應的數(shù)字 85 <----> U ASCII 對應的數(shù)字 86 <----> V ASCII 對應的數(shù)字 87 <----> W ASCII 對應的數(shù)字 88 <----> X ASCII 對應的數(shù)字 89 <----> Y
ASCII 對應的數(shù)字 90 <----> Z ASCII 對應的數(shù)字 91 <----> [ ASCII 對應的數(shù)字 92 <----> \ ASCII 對應的數(shù)字 93 <----> ] ASCII 對應的數(shù)字 94 <----> ^
ASCII 對應的數(shù)字 95 <----> _ ASCII 對應的數(shù)字 96 <----> ` ASCII 對應的數(shù)字 97 <----> a ASCII 對應的數(shù)字 98 <----> b ASCII 對應的數(shù)字 99 <----> c
ASCII 對應的數(shù)字 100 <----> d ASCII 對應的數(shù)字 101 <----> e ASCII 對應的數(shù)字 102 <----> f ASCII 對應的數(shù)字 103 <----> g ASCII 對應的數(shù)字 104 <----> h
ASCII 對應的數(shù)字 105 <----> i ASCII 對應的數(shù)字 106 <----> j ASCII 對應的數(shù)字 107 <----> k ASCII 對應的數(shù)字 108 <----> l ASCII 對應的數(shù)字 109 <----> m
ASCII 對應的數(shù)字 110 <----> n ASCII 對應的數(shù)字 111 <----> o ASCII 對應的數(shù)字 112 <----> p ASCII 對應的數(shù)字 113 <----> q ASCII 對應的數(shù)字 114 <----> r
ASCII 對應的數(shù)字 115 <----> s ASCII 對應的數(shù)字 116 <----> t ASCII 對應的數(shù)字 117 <----> u ASCII 對應的數(shù)字 118 <----> v ASCII 對應的數(shù)字 119 <----> w
ASCII 對應的數(shù)字 120 <----> x ASCII 對應的數(shù)字 121 <----> y ASCII 對應的數(shù)字 122 <----> z

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容