Java String Capitalize capitalize(String string)

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

Description

Return (possibly copy of) given string with first character upper case.

License

Open Source License

Declaration

public static String capitalize(String string) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2008 Charles Rich and Worcester Polytechnic Institute.
 * All Rights Reserved.  Use is subject to license terms.  See the file
 * "license.terms" for information on usage and redistribution of this
 * file and for a DISCLAIMER OF ALL WARRANTIES.
 *///  w  w  w .j av a  2 s.c  o m

public class Main {
    /**
     * Return (possibly copy of) given string with first character upper case.
     */
    public static String capitalize(String string) {
        if (Character.isUpperCase(string.charAt(0)))
            return string;
        char chars[] = string.toCharArray();
        chars[0] = Character.toUpperCase(chars[0]);
        return new String(chars);
    }

    /**
     * Change first character of given string buffer to upper case.
     */
    public static void capitalize(StringBuilder buffer) {
        if (buffer.length() > 0) {
            char first = buffer.charAt(0);
            if (!Character.isUpperCase(first))
                buffer.setCharAt(0, Character.toUpperCase(first));
        }
    }
}

Related

  1. capitalize(String string)
  2. capitalize(String string)
  3. capitalize(String string)
  4. capitalize(String string)
  5. capitalize(String string)
  6. capitalize(String string)
  7. capitalize(String string)
  8. capitalize(String string)
  9. capitalize(String string)