大寫加下划線轉化成小寫駝峰形式


例如把RESULT_LIST轉化成resultList字符串

第一:通過input.toLowerCase().split(spliter)用‘_’把字符串分割成多個小寫字母的數組。

第二:把第一個數組以外的數組首字母變大寫。

第三:通過append()拼接字符串。

 1 //型如XXX_YYY_ZZZ的子串改為xxxYyyZxx的子串
 2     private static String slashToFirstLetterUpper(String input) {
 3         String spliter = "_";
 4         StringBuffer output = new StringBuffer();
 5         String[] words = input.toLowerCase().split(spliter);
 6         for (int i = 0; i < words.length; i++) {
 7             if (i != 0) {
 8                 output.append(fistLetterToUpper(words[i]));
 9             }
10             else {
11                 output.append(words[i]);
12             }
13         }
14 
15         return output.toString();
16     }
17 
18     private static String fistLetterToUpper(String input) {
19         if (input == null)
20             return "";
21         if (input.length() <= 0)
22             return "";
23 
24         return input.substring(0, 1).toUpperCase() + input.substring(1);
25     }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM