Here you can find the source of titleCase(final String s)
public static String titleCase(final String s)
//package com.java2s; //License from project: Open Source License public class Main { public static String titleCase(final String s) { if (s == null || s.length() == 0) { return s; } else if (s.length() == 1) { return s.toUpperCase(); } else {/* w w w .j a v a2 s .c o m*/ StringBuilder result = new StringBuilder(s.length()); String delim = ""; for (String eachPart : s.split(" ")) { result.append(delim); delim = " "; if (eachPart.length() < 2) { result.append(eachPart); } else { result.append(eachPart.substring(0, 1).toUpperCase()) .append(eachPart.substring(1).toLowerCase()); } } return result.toString(); } } }