Here you can find the source of capitalize(String in)
Parameter | Description |
---|---|
in | - string to capitalize |
public static String capitalize(String in)
//package com.java2s; //License from project: Apache License public class Main { /**{ method/*from w w w.ja v a2 s . c o m*/ @name capitalize @function - test of the object test is a member of the list data @param in - string to capitalize @return - non-null capitailzed string }*/ public static String capitalize(String in) { if (in.length() == 0) return (""); StringBuffer s = new StringBuffer(in.length()); int i = 0; char c = in.charAt(i++); while (c <= ' ') { c = in.charAt(i++); if (i >= in.length()) return (""); } s.append(Character.toUpperCase(c)); boolean atSpace = false; for (; i < in.length(); i++) { c = Character.toLowerCase(in.charAt(i)); if (c == ' ') { atSpace = true; } else { if (atSpace) { if (c > ' ') { c = Character.toUpperCase(c); atSpace = false; } } } s.append(c); } return (s.toString()); } /**{ method @name toString @function convert a char to a string @param c the char @return the String }*/ public static String toString(char c) { StringBuffer s = new StringBuffer(); s.append(c); return (s.toString()); } }