Here you can find the source of toTitleCase(final String input)
Parameter | Description |
---|---|
input | string to edit |
Parameter | Description |
---|---|
IllegalArgumentException | if Input is null or empty |
public static String toTitleCase(final String input)
//package com.java2s; //License from project: Creative Commons License public class Main { /**/*from w w w . jav a 2s . com*/ * Capitalizes all words in a string. * @param input string to edit * @return string with all words capitalized * @throws IllegalArgumentException if Input is null or empty */ public static String toTitleCase(final String input) { if (input == null || input.isEmpty()) throw new IllegalArgumentException("Input cannot be null or empty!"); final String[] words = input.trim().split(" "); final StringBuilder sb = new StringBuilder(); for (final String word : words) { sb.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1)).append(' '); } return sb.toString().trim(); } }