Java String Capitalize capitalize(String name)

Here you can find the source of capitalize(String name)

Description

This method capitalizes the first character in the provided string.

License

Open Source License

Return

resulted string

Declaration

public static String capitalize(String name) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w w  w  .j ava  2s  . c  o m
     * This method capitalizes the first character in the provided string.
     * @return resulted string
     */
    public static String capitalize(String name) {

        int len = name.length();
        StringBuffer sb = new StringBuffer(len);
        boolean setCap = true;
        for (int i = 0; i < len; i++) {
            char c = name.charAt(i);
            if (c == '-' || c == '_') {
                setCap = true;
            } else {
                if (setCap) {
                    sb.append(Character.toUpperCase(c));
                    setCap = false;
                } else {
                    sb.append(c);
                }
            }
        }

        return sb.toString();
    }
}

Related

  1. capitalize(String message)
  2. capitalize(String name)
  3. capitalize(String name)
  4. capitalize(String name)
  5. capitalize(String name)
  6. capitalize(String name)
  7. capitalize(String name)
  8. capitalize(String name)
  9. capitalize(String orig)