Java 大写字母转下划线加小写字母

为什么80%的码农都做不了架构师?>>>   hot3.png

public static String camel4underline(String param){
    Pattern p=Pattern.compile("[A-Z]");
    if(param==null ||param.equals("")){
        return "";
    }
    StringBuilder builder=new StringBuilder(param);
    Matcher mc=p.matcher(param);
    int i=0;
    while(mc.find()){
        builder.replace(mc.start()+i, mc.end()+i, "_"+mc.group().toLowerCase());
        i++;
    }

    if('_' == builder.charAt(0)){
        builder.deleteCharAt(0);
    }
    return builder.toString();
}

转载于:https://my.oschina.net/muziH/blog/1556890

你可能感兴趣的:(Java 大写字母转下划线加小写字母)