下滑线转换为驼峰

下划线转驼峰

 1 public static Object underline2Camel(String line,boolean smallCamel){
 2         if(line==null||"".equals(line)){
 3             return "";
 4         }
 5         StringBuffer sb=new StringBuffer();
 6         Pattern pattern=Pattern.compile("([A-Za-z\d]+)(_)?");
 7         Matcher matcher=pattern.matcher(line);
 8         while(matcher.find()){
 9             String word=matcher.group();
10             sb.append(smallCamel&&matcher.start()==0?Character.toLowerCase(word.charAt(0)):Character.toUpperCase(word.charAt(0)));
11             int index=word.lastIndexOf('_');
12             if(index>0){
13                 sb.append(word.substring(1, index).toLowerCase());
14             }else{
15                 sb.append(word.substring(1).toLowerCase());
16             }
17         }
18         return sb.toString();
19     }
原文地址:https://www.cnblogs.com/LifeFruit/p/13839088.html