Here you can find the source of toSentenceCase(String inputString)
public static String toSentenceCase(String inputString)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w .java 2 s . co m * BETA VERSION: converts an URL to UpperCamelCase * TODO: test the correct behavior */ public static String toSentenceCase(String inputString) { String result = ""; if (inputString.length() == 0) { return result; } char firstChar = inputString.charAt(0); char firstCharToUpperCase = Character.toUpperCase(firstChar); result = result + firstCharToUpperCase; boolean terminalCharacterEncountered = false; char[] terminalCharacters = { '.', '?', '!', '_', ' ', '-' }; for (int i = 1; i < inputString.length(); i++) { char currentChar = inputString.charAt(i); if (terminalCharacterEncountered) { if (currentChar == ' ') { result = result + currentChar; } else { char currentCharToUpperCase = Character.toUpperCase(currentChar); result = result + currentCharToUpperCase; terminalCharacterEncountered = false; } } else { char currentCharToLowerCase = Character.toLowerCase(currentChar); result = result + currentCharToLowerCase; } for (int j = 0; j < terminalCharacters.length; j++) { if (currentChar == terminalCharacters[j]) { terminalCharacterEncountered = true; break; } } } result = result.replaceAll("-", ""); return result; } }