Browse Source

Add StringUtil.capitalize() method

master
Carpenter Lee 6 years ago
parent
commit
bbea62a5c7
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/StringUtil.java

+ 18
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/StringUtil.java View File

@@ -117,4 +117,22 @@ public final class StringUtil {


return true; return true;
} }

public static String capitalize(String str) {
return changeFirstCharacterCase(str, true);
}

private static String changeFirstCharacterCase(String str, boolean capitalize) {
if (str == null || str.length() == 0) {
return str;
}
StringBuilder buf = new StringBuilder(str.length());
if (capitalize) {
buf.append(Character.toUpperCase(str.charAt(0)));
} else {
buf.append(Character.toLowerCase(str.charAt(0)));
}
buf.append(str.substring(1));
return buf.toString();
}
} }

Loading…
Cancel
Save