java string 中首字母改成大写
//方法一、 首字母大写 先将首字母截取, 转化成大写然后再串起来
public static void main(String[] args) {
String name = "apple";
System.out.println(new Text().captureName(name));
}
public static String captureName(String name) {
name = name.substring(0, 1).toUpperCase() + name.substring(1);
return name;
}
//方法二、 首字母大写 进行字母的ascii编码前移
public static void main(String[] args) {
String name = "apple";
System.out.println(new Text().captureName(name));
}
public static String captureName(String name) {
// name = name.substring(0, 1).toUpperCase() + name.substring(1);
// return name;
char[] cs=name.toCharArray();
cs[0]-=32;
return String.valueOf(cs);
}
资料来源网络收集整理,用于复习