Here you can find the source of capitalize(String name)
Parameter | Description |
---|---|
name | The string to be capitalized. |
public static String capitalize(String name)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w ww . j a v a2 s . c o m*/ * Thus "fooBah" becomes "FooBah" and "X" becomes "X". * * @param name * The string to be capitalized. * @return The capitalized version of the string. */ public static String capitalize(String name) { if (name.length() == 0) { return name; } if (Character.isUpperCase(name.charAt(0))) { return name; } char chars[] = name.toCharArray(); char c = chars[0]; char modifiedChar = Character.toUpperCase(c); if (modifiedChar == c) { return name; } chars[0] = modifiedChar; return new String(chars); } }