Here you can find the source of capitalized(String s)
Parameter | Description |
---|---|
s | a parameter |
public static String capitalized(String s)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by public class Main { /**//from ww w .ja v a 2 s . c o m * @param s * @return s with the first character of s (if any) in upper case. * @postcondition isNullOrEmpty(s) --> LangUtils.equals(result, s) */ public static String capitalized(String s) { return isNullOrEmpty(s) ? s : s.substring(0, 1).toUpperCase() + s.substring(1); } /** * @param s * @return Is s <code>null</code> or empty? * @postcondition result <--> (s == null) || (s.length() == 0) */ public static boolean isNullOrEmpty(String s) { return (s == null || s.length() == 0); } /** * Locale-independent variant of {@link String#toUpperCase()}. * This method works on {@code char} level and hence uses a locale-independent * character mapping as defined by the Unicode standard. */ public static String toUpperCase(String s) { StringBuilder sb = new StringBuilder(s); for (int i = 0, len = sb.length(); i < len; i++) { char ch = sb.charAt(i); char ch2 = Character.toUpperCase(ch); if (ch != ch2) sb.setCharAt(i, ch2); } return sb.toString(); } }