Here you can find the source of capitalizeFirstLetter(String s)
Parameter | Description |
---|---|
s | String to capitalize. |
public static String capitalizeFirstLetter(String s)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /** Capitalize first letter in string. */* w w w.ja va2 s.com*/ * @param s String to capitalize. * * @return "s" with first letter (not first character) capitalized. * Remaining characters are set to lower case. */ public static String capitalizeFirstLetter(String s) { char[] chars = s.toLowerCase().toCharArray(); for (int i = 0; i < chars.length; i++) { char ch = chars[i]; if (Character.isLetter(ch)) { chars[i] = Character.toUpperCase(ch); break; } } return new String(chars); } /** Check if character is a letter. * * @param c Character to test. * * @return true if character is a letter. */ public static boolean isLetter(char c) { return Character.isLetter(c); } /** Check if string is a single letter. * * @param s String to test. * * @return true if string is a single letter. */ public static boolean isLetter(String s) { return (s != null) && (s.length() == 1) && Character.isLetter(s.charAt(0)); } }