Here you can find the source of capitalizeAllFirstChar(String text)
Parameter | Description |
---|---|
text | a parameter |
public static String capitalizeAllFirstChar(String text)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w.ja v a2 s .co m * Sample1: S E S submit date -> S E S Submit Date * @param text * @return */ public static String capitalizeAllFirstChar(String text) { if (text != null) { StringBuilder builder = new StringBuilder(text); for (int i = 0, count = builder.length(); i < count; i++) { char c = builder.charAt(i); if (i == 0) { if (c >= 97 && c <= 122) { builder.deleteCharAt(i); builder.insert(i, Character.toUpperCase(c)); } } else if (c == ' ' && i < count - 1) { int j = i + 1; char r = builder.charAt(j); if (r >= 97 && r <= 122) { builder.deleteCharAt(j); builder.insert(j, Character.toUpperCase(r)); } } } return builder.toString(); } return text; } }