Java String Capitalize capitalize(String s)

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

Description

Returns a version of the supplied string with the first letter capitalized.

License

Open Source License

Declaration

public static String capitalize(String s) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

public class Main {
    /**//w w  w  .  j  ava 2 s  .  com
     * Returns a version of the supplied string with the first letter capitalized.
     */
    public static String capitalize(String s) {
        if (isBlank(s)) {
            return s;
        }
        char c = s.charAt(0);
        if (Character.isUpperCase(c)) {
            return s;
        } else {
            return String.valueOf(Character.toUpperCase(c)) + s.substring(1);
        }
    }

    /**
     * Returns true if the supplied string is null, zero length, or contains only whitespace.
     */
    public static boolean isBlank(String text) {
        return (text == null) || (text.trim().length() == 0);
    }
}

Related

  1. capitalize(String pString)
  2. capitalize(String s)
  3. capitalize(String s)
  4. capitalize(String s)
  5. capitalize(String s)
  6. capitalize(String s)
  7. capitalize(String s)
  8. capitalize(String s)
  9. capitalize(String s)