public class FirstLetterUppercase { public static void main(String[] args){
System.out.println(new FirstLetterUppercase().upperFirstLatter("letter"));
System.out.println(new FirstLetterUppercase().upperFirstLatter2("letter"));、
} /**
* 方法一
* @param letter
* @return
*/
public String upperFirstLatter(String letter){
char[] chars = letter.toCharArray();
if(chars[0]>='a' && chars[0]<='z'){
chars[0] = (char) (chars[0]-32);
}
return new String(chars);
} /**
* 方法二
* @param letter
* @return
*/
public String upperFirstLatter2(String letter){
return letter.substring(0, 1).toUpperCase()+letter.substring(1);
} }