/**
* 把骆驼命名法的变量,变为大写字母变小写且之前加下划线
*
* @param str
* @return
*/
public static String toUnderline(String str) {
str = StringUtils.uncapitalize(str);
char[] letters = str.toCharArray();
StringBuilder sb = new StringBuilder();
for (char letter : letters) {
if (Character.isUpperCase(letter)) {
sb.append("_" + letter + "");
} else {
sb.append(letter + "");
}
}
return StringUtils.lowerCase(sb.toString());
}
原文地址:https://www.cnblogs.com/robinAndLaurel/p/9830229.html
时间: 2024-10-14 09:26:37