Java String Capitalize capitalized(String s)

Here you can find the source of capitalized(String s)

Description

capitalized

License

Open Source License

Parameter

Parameter Description
s a parameter

Return

s with the first character of s (if any) in upper case.

Declaration

public static String capitalized(String s) 

Method Source Code

//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();
    }
}

Related

  1. capitalize(String word)
  2. capitalize(String words)
  3. capitalize(StringBuilder text)
  4. capitalizeAt(StringBuilder builder, int index)
  5. capitalizeClass(String className)
  6. capitalized(String s)
  7. capitalized(String str)
  8. capitalizeD(String str, char[] delimiters)
  9. capitalizedArray(String[] sstr)