瀏覽代碼

Add StringUtil.capitalize() method

master
Carpenter Lee 6 年之前
父節點
當前提交
bbea62a5c7
共有 1 個檔案被更改,包括 18 行新增0 行删除
  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 查看文件

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

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…
取消
儲存