Here you can find the source of toTitleCase(String input, boolean eachWord)
Parameter | Description |
---|---|
input | the string input |
eachWord | true to indicate each word should be put into title case |
public static String toTitleCase(String input, boolean eachWord)
//package com.java2s; public class Main { /**/*from ww w. j av a 2 s . c o m*/ * @param input the string input * @param eachWord true to indicate each word should be put into title case * @return the string capitalized */ public static String toTitleCase(String input, boolean eachWord) { StringBuilder titleCase = new StringBuilder(); boolean nextTitleCase = true; for (char c : input.toCharArray()) { if (Character.isSpaceChar(c) && eachWord) { nextTitleCase = true; } else if (nextTitleCase) { c = Character.toTitleCase(c); nextTitleCase = false; } else { c = Character.toLowerCase(c); } titleCase.append(c); } return titleCase.toString(); } }