Java String Capitalize capitalize(String to_capitalize)

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

Description

This method capitalizes the first letter of the given String.

License

Open Source License

Parameter

Parameter Description
to_capitalize is the <tt>String</tt> to be capitalized.

Return

the given String with the first character capitalized (if it is a letter).

Declaration

public static String capitalize(String to_capitalize) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** This method capitalizes the first letter of the given <tt>String</tt>.
     * /*from w  w  w . j a v  a  2 s.  c o  m*/
     * @param to_capitalize
     *            is the <tt>String</tt> to be capitalized.
     * @return the given <tt>String</tt> with the first character capitalized (if it is a letter). */
    public static String capitalize(String to_capitalize) {
        if (to_capitalize == null || to_capitalize.equals(""))
            return to_capitalize;
        else if (to_capitalize.length() == 1)
            return to_capitalize.toUpperCase();
        else
            return to_capitalize.substring(0, 1).toUpperCase() + to_capitalize.substring(1);
    }

    public static String substring(String string, String beginning, String end) {
        if (!string.contains(beginning) || !string.contains(end)
                || string.indexOf(beginning) >= string.indexOf(end))
            return null;
        else {
            String after_beginning = string.substring(string.indexOf(beginning) + beginning.length());
            return after_beginning.substring(0, after_beginning.indexOf(end));
        }
    }
}

Related

  1. capitalize(String text)
  2. capitalize(String text)
  3. capitalize(String text)
  4. capitalize(String text)
  5. capitalize(String texte)
  6. capitalize(String token)
  7. Capitalize(String val)
  8. capitalize(String value)
  9. capitalize(String value)