比如字符串java,我现在要得到Java。。。用啥办法最好呢?
我现在是这样做的。。但是感觉有点别扭?用replace怎么样?还有其他更优雅的方法吗?
String first = fldName.substring(0, 1).toUpperCase();
String rest = fldName.substring(1, fldName.length());
String newStr = new StringBuffer(first).append(rest).toString();
------解决方案--------------------
StringBuilding sb = new StringBuilding(str);
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
str = sb.toString();
------解决方案--------------------
- Java code
//首字母转小写 public static String toLowerCaseFirstOne(String s) { if(Character.isLowerCase(s.charAt(0))) return s; else return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString(); } //首字母转大写 public static String toUpperCaseFirstOne(String s) { if(Character.isUpperCase(s.charAt(0))) return s; else return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString(); }