Here you can find the source of toUpperCaseFirstAll(String text)
Parameter | Description |
---|---|
text | the text to modify |
public static String toUpperCaseFirstAll(String text)
//package com.java2s; //License from project: Open Source License public class Main { /**//ww w . jav a2 s.c o m * Changes the first character of all words in the given text to uppercase. * * @param text the text to modify * @return the text with all words capitalized */ public static String toUpperCaseFirstAll(String text) { StringBuilder result = new StringBuilder(); String[] words = text.split("\\s"); for (int i = 0; i < words.length; i++) { result.append(toUpperCaseFirst(words[i])); if (i < words.length - 1) { result.append(" "); } } return result.toString(); } /** * Changes the first character of the given text to upper case. * * @param text the text which should be capitalized. * @return the capitalized text. */ public static String toUpperCaseFirst(String text) { char[] charArray = text.toCharArray(); charArray[0] = Character.toUpperCase(charArray[0]); return String.valueOf(charArray); } }