Upper case first letter in string - Android java.lang

Android examples for java.lang:String Case

Description

Upper case first letter in string

Demo Code

import android.text.TextUtils;
import android.widget.TextView;
import java.util.Calendar;

public class Main{

    /**//w w w .  j  a  va  2s  .c  om
     * Upper case first letter in string
     *
     * @param str
     * @return
     */
    public static String UppercaseFirstLetters(String str) {
        boolean prevWasWhiteSp = true;
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (Character.isLetter(chars[i])) {
                if (prevWasWhiteSp) {
                    chars[i] = Character.toUpperCase(chars[i]);
                }
                prevWasWhiteSp = false;
            } else {
                prevWasWhiteSp = Character.isWhitespace(chars[i]);
            }
        }
        return new String(chars);
    }

}

Related Tutorials