请问有什么办法将 String[] strings = {"ORG_ID","USER_ID","SHOW_ORDER","EMAIL_STATUSLSC","OFFICE_PHONE","LOGON_NAME","JOB_TYPE","SEX","IS_MOBILE_PLATE_OPEN","USER_NAME","IS_JOB_RECORD_TJ","USER_JOB_ID","MOBILE"};这个字符串数组中的字符串内容改成大小驼峰吗
时间: 2023-07-07 09:43:41 浏览: 151
可以使用以下代码将该字符串数组中的字符串内容改成大小驼峰:
```java
public static String toCamelCase(String str) {
if (str == null || str.isEmpty()) {
return str;
}
StringBuilder sb = new StringBuilder();
boolean capitalizeNext = false;
for (char c : str.toCharArray()) {
if (c == '_') {
capitalizeNext = true;
} else if (capitalizeNext) {
sb.append(Character.toUpperCase(c));
capitalizeNext = false;
} else {
sb.append(Character.toLowerCase(c));
}
}
return sb.toString();
}
public static String toUpperCamelCase(String str) {
String camelCase = toCamelCase(str);
return camelCase.substring(0, 1).toUpperCase() + camelCase.substring(1);
}
public static void main(String[] args) {
String[] strings = {"ORG_ID","USER_ID","SHOW_ORDER","EMAIL_STATUSLSC","OFFICE_PHONE","LOGON_NAME","JOB_TYPE","SEX","IS_MOBILE_PLATE_OPEN","USER_NAME","IS_JOB_RECORD_TJ","USER_JOB_ID","MOBILE"};
for (int i = 0; i < strings.length; i++) {
strings[i] = toUpperCamelCase(strings[i]);
}
System.out.println(Arrays.toString(strings));
}
```
输出结果为:
```
[OrgId, UserId, ShowOrder, EmailStatuslsc, OfficePhone, LogonName, JobType, Sex, IsMobilePlateOpen, UserName, IsJobRecordTj, UserJobId, Mobile]
```
其中,`toCamelCase()`方法将下划线分隔的单词转换为小驼峰命名法,`toUpperCamelCase()`方法将小驼峰命名法转换为大驼峰命名法,最后在`main()`方法中遍历字符串数组,依次调用这两个方法将字符串转换为大小驼峰命名法。
阅读全文