Here you can find the source of capitalize(final String str)
Parameter | Description |
---|---|
str | a parameter |
public static String capitalize(final String str)
//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)); } }