JAVA 小工具
驼峰命名转下划线命名
public static String parsingCamelCaseToUnderline(String params){ char[] charArray = params.toCharArray(); params = ""; for (int i = 0; i < charArray.length; i++) { char c = charArray[i]; if( i == 0 ){ params += Character.toLowerCase(c); }else{ params += (Character.isUpperCase(c) ? "_" + Character.toLowerCase(c) : c); } } return params; }
示例:
System.out.println(parsingCamelCaseToUnderline("createTime")); System.out.println(parsingCamelCaseToUnderline("CreateTime")); System.out.println(parsingCamelCaseToUnderline("UreateTime")); console ...... create_time create_time ureate_time