Java 驼峰转下划线
public static String camelCase2LineSeparation(String camelWord) {
Matcher matcher = Pattern.compile("([A-Z][a-z])|([a-z][A-Z])").matcher(camelWord);
StringBuffer word = new StringBuffer();
while (matcher.find()){
matcher.appendReplacement(word, matcher.group(0).replaceAll("(.$)", "_$1"));
}
matcher.appendTail(word);
return word.toString().toUpperCase();
}
public static String upperCamelCase2LineSeparation(String upperCamelWord) {
Matcher matcher = Pattern.compile("[A-Z]").matcher(upperCamelWord);
StringBuffer word = new StringBuffer();
while (matcher.find()){
matcher.appendReplacement(word, matcher.group(0).toUpperCase() + "_");
}
matcher.appendTail(word);
return word.toString().toUpperCase();
}
学习记录,方便复习