我意识到GoogleMaps中的AdminArea名称使用小写字母(至少在波兰使用),因此我决定在我的新应用(非常简单)中以大写字母开头看起来会更好。 这段代码有意义吗?它对我有用,但是我不确定这是否是最好的方法:
String firstLetter = listAddresses.get(0).getAdminArea().toUpperCase().charAt(0)+"";
String otherLetters = listAddresses.get(0).getAdminArea().substring(1);
String adminArea = firstLetter+otherLetters;
答案 0 :(得分:1)
考虑:org.apache.commons.lang3.StringUtils.capitalize:
public static String capitalize(final String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return str;
}
final char firstChar = str.charAt(0);
final char newChar = Character.toTitleCase(firstChar);
if (firstChar == newChar) {
// already capitalized
return str;
}
char[] newChars = new char[strLen];
newChars[0] = newChar;
str.getChars(1,strLen, newChars, 1);
return String.valueOf(newChars);
}