9910

单飞

   :: 首页 :: 联系 :: 聚合  :: 管理
1 private static String getMethodName(String fildeName){
2 byte[] items = fildeName.getBytes();
3 items[0= (byte)((char)items[0]-'a'+'A');;
4 return new String(items);
5 }


效率是最高的.
posted on 2012-03-20 17:15 单飞 阅读(2868) 评论(1)  编辑  收藏 所属分类: java

Feedback

# re: 把字符串第一个字母大写 2012-03-21 13:42 小明
用bytes涉及到编码转化,可能要慢一点,另外,如果第一个字符是中文,会是什么情况?用char要安全多了。

更简单的写法:
private static String getMethodName(String fildeName){
char[] chars =fildeName.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
}  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: