Java examples for java.lang:String Capitalize
Capitalize a string by using Character.toTitleCase
public class Main { public static void main(String[] argv) { String str = "java2s.com"; System.out.println(capitalize(str)); }//from w w w . j ava 2 s .c o m public static String capitalize(String str) { if (str == null || str.isEmpty()) { return ""; } char[] buffer = str.toCharArray(); buffer[0] = Character.toTitleCase(buffer[0]); return new String(buffer); } }