java去除下划線並首字母大寫


(將如TEST_TB_KKK_LLLL 轉換為    testTbKkkLlll)
 
public static Map<String, Object> zh(Map<String,Object> map) {
        HashMap<String, Object> newMap = new HashMap<String, Object>();
        for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = (String) entry.getValue();
            String newKey = key.toLowerCase();
            StringBuffer sbf = new StringBuffer();
            if (newKey.contains("_"))
            {
                // 按下划線來切割字符串為數組
                String[] split = newKey.split("_");
                // 循環數組操作其中的字符串
                for (int i = 0, index = split.length; i < index; i++){
                    char[] ch = split[i].toCharArray();
                    if(i>0){
                        ch[0] = (char) (ch[0] - 32);
                    }
                    // 添加到字符串緩沖區
                    sbf.append(ch);
                }
            }else{
                sbf.append(newKey);
            }
            newMap.put(sbf.toString(), value);
        }
        return newMap;
    }

 


免責聲明!

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



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