Java String Capitalize capitalize(final String str)

Here you can find the source of capitalize(final String str)

Description

Put first letter into uppercase

License

Open Source License

Parameter

Parameter Description
str a parameter

Return

transformated string

Declaration

public static String capitalize(final String str) 

Method Source Code

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

public class Main {
    /**/*from   www  .j a  v a2s. co m*/
     * Put first letter into uppercase
     *
     * @param str
     * @return transformated string
     */
    public static String capitalize(final String str) {
        if (str.length() > 1) {
            return str.substring(0, 1).toUpperCase() + str.substring(1);
        } else {
            return str.toUpperCase();
        }
    }

    /**
     * a 'safe' @link {@link String#substring(int, int)} that does not throw exceptions when indexes are false.
     *
     * @param s
     *            any string
     * @param startIndex
     *            start index (maybe greater that endIndex)
     * @param endIndex
     *            required end index (may greater that the string itself)
     * @return substring
     */
    public static String substring(final String s, int startIndex, int endIndex) {
        startIndex = Math.min(s.length(), Math.max(0, startIndex));
        endIndex = Math.min(s.length(), Math.max(0, endIndex));
        return s.substring(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex));
    }
}

Related

  1. capitalize(final String str)
  2. capitalize(final String str)
  3. capitalize(final String str)
  4. capitalize(final String str)
  5. capitalize(final String str)
  6. capitalize(final String str)
  7. capitalize(final String str)
  8. capitalize(final String str, final char... delimiters)
  9. capitalize(final String text)