首页 > 编程语言 >JAVA 小工具

JAVA 小工具

时间:2022-12-06 16:31:45浏览次数:45  
标签:JAVA Character System charArray params parsingCamelCaseToUnderline 工具 out

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


标签:JAVA,Character,System,charArray,params,parsingCamelCaseToUnderline,工具,out
From: https://blog.51cto.com/u_15904161/5916381

相关文章