Here you can find the source of capitalize(String str)
public static String capitalize(String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String capitalize(String str) { char[] chars = str.toCharArray(); boolean sentenceStart = true; for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (sentenceStart) { if (c >= 'a' && c <= 'z') { chars[i] -= 0x20;//from w w w.ja v a 2 s. com sentenceStart = false; } else if (c >= 'A' && c <= 'Z') { sentenceStart = false; } } else { if (c >= 'A' && c <= 'Z') { chars[i] += 0x20; } } if (c == '.' || c == '!' || c == '?') { sentenceStart = true; } } return new String(chars, 0, chars.length); } }