Java String Capitalize capitalize(String str)

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

Description

capitalize

License

Apache License

Declaration

public static String capitalize(String str) 

Method Source Code

//package com.java2s;
/*/*  www .j  ava2 s.c om*/
 * Copyright 2008-2009 MOPAS(Ministry of Public Administration and Security).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

public class Main {
    public static String capitalize(String str) {
        return !isNull(str) ? str.substring(0, 1).toUpperCase()
                + str.substring(1).toLowerCase() : str;
    }

    /**
     * @param str
     * @return
     */
    public static boolean isNull(String str) {

        if (str != null) {
            str = str.trim();
        }

        return (str == null || "".equals(str));
    }

    /**
     * @param str
     * @return
     */
    public static String trim(String str) {
        return str.trim();
    }

    /**
     * If original String has a specific String, remove
     * specific Strings from original String.
     * 
     * <pre>
     * StringUtil.trim('pass*word', '*') = 'password'
     * </pre>
     * @param origString
     *        original String
     * @param trimString
     *        String to be trimmed
     * @return converting result
     */
    public static String trim(String origString, String trimString) {
        int startPosit = origString.indexOf(trimString);
        if (startPosit != -1) {
            int endPosit = trimString.length() + startPosit;
            return origString.substring(0, startPosit)
                    + origString.substring(endPosit);
        }
        return origString;
    }

    /**
     * @param source
     * @param target
     * @return
     */
    public static boolean equals(String source, String target) {

        return null2void(source).equals(null2void(target));

    }

    /**
     * @param str
     * @return
     */
    public static String null2void(String str) {

        if (isNull(str)) {
            str = "";
        }

        return str;
    }
}

Related

  1. capitalize(String s)
  2. capitalize(String s, char delimiter)
  3. capitalize(String s, String fullstring)
  4. capitalize(String source)
  5. capitalize(String src)
  6. capitalize(String str)
  7. capitalize(String str)
  8. capitalize(String str)
  9. capitalize(String str)