Android examples for java.lang:String Case
capitalize string and handle null value
public class Main { /**// w w w . j a va 2 s .c om * <pre> * StringUtil.capitalize(null) = null * StringUtil.capitalize("Han") = "Han" * StringUtil.capitalize("han") = "Han" * </pre> * */ public static String capitalize(String str) { if (str == null) { return null; } char[] charArray = str.toCharArray(); if (charArray.length > 0) { charArray[0] = Character.toUpperCase(charArray[0]); } return new String(charArray); } }