将一个驼峰命名转换成由多个单词组成的变量名的变量名:例如:将helloWorld转换成hello_world
public class Client {
public static String toHump(String str) {
String rs = "";
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (Character.isUpperCase(c)) {
rs += "_" + Character.toLowerCase(c);
} else {
rs += c;
}
}
return rs;
}
public static void main(String[] args) {
String str = "helloWorld"; // hello_world
System.out.println(toHump(str));
}
}