java.beans提供的方法
Introspector.decapitalize("Abc")
public static String decapitalize(String name) {
if (name == null || name.length() == 0) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))){
return name;
}
char chars[] = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))){
return name;
}
注意:如果首字母和第二个字母都是大写 不做处理 如
Introspector.decapitalize("ABc")
返回ABc
Introspector.decapitalize("Abc")
返回abc