Java String Capitalize capitalize(String word)

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

Description

Capitalize the first word of the passed String.

License

Apache License

Declaration

public static String capitalize(String word) 

Method Source Code

//package com.java2s;
/*/*w  w  w .j a va  2s. c o  m*/
 * StringUtil.java
 *
 * This file is part of SQL Workbench/J, http://www.sql-workbench.net
 *
 * Copyright 2002-2017, Thomas Kellerer
 *
 * Licensed under a modified Apache License, Version 2.0
 * that restricts the use for certain governments.
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at.
 *
 *     http://sql-workbench.net/manual/license.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * To contact the author please send an email to: support@sql-workbench.net
 *
 */

public class Main {
    /**
     * Capitalize the first word of the passed String.
     * (write the first character in uppercase, the rest in lower case)
     * This does not loop through the entire string to capitalize every word.
     */
    public static String capitalize(String word) {
        if (word == null)
            return null;
        if (word.length() == 0)
            return word;
        StringBuilder s = new StringBuilder(word.toLowerCase());
        char c = s.charAt(0);
        s.setCharAt(0, Character.toUpperCase(c));
        return s.toString();
    }

    public static String[] toUpperCase(String[] source) {
        if (source == null)
            return source;
        String[] result = new String[source.length];
        for (int i = 0; i < source.length; i++) {
            result[i] = source[i] == null ? null : source[i].toUpperCase();
        }
        return result;
    }
}

Related

  1. capitalize(String value)
  2. capitalize(String value)
  3. capitalize(String var)
  4. capitalize(String word)
  5. capitalize(String word)
  6. capitalize(String word)
  7. capitalize(String word)
  8. capitalize(String word)
  9. capitalize(String word)