Pārlūkot izejas kodu

Add StringUtil.capitalize() method

master
Carpenter Lee pirms 6 gadiem
vecāks
revīzija
bbea62a5c7
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  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 Parādīt failu

@@ -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();
}
}

Notiek ielāde…
Atcelt
Saglabāt