Java String Capitalize capitalise(String string)

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

Description

Capitalizes the first letter of a String

License

Open Source License

Parameter

Parameter Description
string the String to be capitalized

Return

capitalized String

Declaration

public static String capitalise(String string) 

Method Source Code

//package com.java2s;
/*/*from   ww  w  .j  ava  2 s. co m*/
 * This file is part of Nexus.
 *
 * Nexus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Nexus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Nexus.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Capitalizes the first letter of a String
     *
     * @param string the String to be capitalized
     * @return capitalized String
     */
    public static String capitalise(String string) {
        String[] parts = string.split(" ");
        for (int i = 0; i < parts.length; i++) {
            parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1);
        }
        return combineSplit(0, parts, " ");
    }

    public static String combineSplit(int startIndex, String[] string, String separator) {
        if (string == null || startIndex >= string.length) {
            return "";
        } else {
            StringBuilder builder = new StringBuilder();
            for (int i = startIndex; i < string.length; i++) {
                builder.append(string[i]);
                builder.append(separator);
            }
            builder.delete(builder.length() - separator.length(), builder.length());
            return builder.toString();
        }
    }
}

Related

  1. capitalise(String s)
  2. capitalise(String s)
  3. capitalise(String str)
  4. capitalise(String str)
  5. capitalise(String str)
  6. capitalise(String string)
  7. capitalise(String string)
  8. capitalise(String toCapitalise)
  9. capitaliseAndCheckBases(byte[] bases, boolean strict)