java实现下划线转驼峰

废话少说,直接上代码

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Temp {
    public static void main(String[] args) {
        String str = "ASSET_TYPE_CODE";
        str = str.toLowerCase();
        final StringBuffer sb = new StringBuffer();
        Pattern p = Pattern.compile("_(\\w)");
        Matcher m = p.matcher(str);
        while (m.find()){
            m.appendReplacement(sb,m.group(1).toUpperCase());
        }
        m.appendTail(sb);
        System.out.println(sb.toString());
    }
}
posted @ 2017-11-25 16:06  不自然地坚持  阅读(5583)  评论(0编辑  收藏  举报