Here you can find the source of capitalize(String var)
public static String capitalize(String var)
//package com.java2s; //License from project: Apache License public class Main { public static String capitalize(String var) { return capitalize(var, false); }//w w w . j av a 2 s. co m public static String capitalize(String var, boolean camelCaseUnderScore) { if (var == null) return null; if (camelCaseUnderScore) { var = camelCaseUnderscores(var); } String char1 = var.substring(0, 1); String rest = var.substring(1, var.length()); char1 = char1.toUpperCase(); return char1 + rest; } public static String camelCaseUnderscores(String str) { StringBuffer buff = new StringBuffer(); boolean capitalize = false; boolean doAppend = false; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (capitalize) { ch = Character.toUpperCase(ch); doAppend = true; } if (ch == '_') { capitalize = true; doAppend = false; } else { capitalize = false; doAppend = true; } if (doAppend) { buff.append(ch); } } return buff.toString(); } }