Java String Uncapitalize uncapitalizeWord(String word)

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

Description

Convert the initial of given string word to lower case.

License

Apache License

Parameter

Parameter Description
word the string to convert

Return

if given string is a valid string, then return string with lower case initial character, otherwise return the input string.

Declaration

public static String uncapitalizeWord(String word) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**// www  .  j  av a 2  s.  com
     * Convert the initial of given string <code>word</code> to lower case.
     * <p>
     * Examples:
     * <blockquote><pre>
     * StringUtil.uncapitalizeWord("hello") return "Hello"
     * StringUtil.uncapitalizeWord("World") return "World"
     * StringUtil.uncapitalizeWord("  ") return "  "
     * StringUtil.uncapitalizeWord(null) return null
     * </pre></blockquote>
     * @param word the string to convert
     * @return if given string is a valid string, then  return string with
     * lower case initial character, otherwise return the input string.
     */
    public static String uncapitalizeWord(String word) {
        String result = null;

        if (isValid(word)) {
            result = word.substring(0, 1).toLowerCase() + word.substring(1);
        } else {
            return word;
        }

        return result;
    }

    /**
     * Verify whether the given string <code>str</code> is valid. If the given
     * string is not null and contains any alphabet or digit, then the string
     * is think as valid, otherwise invalid.
     * @param str string to verify
     * @return false if the given string is null or contains only empty character,
     * otherwise return true.
     */
    public static boolean isValid(String str) {
        boolean valid = true;

        if ((str == null) || (str.trim().length() <= 0)) {
            valid = false;
        }

        return valid;
    }
}

Related

  1. unCapitalizeClass(String className)
  2. uncapitalized(String aString)
  3. uncapitalizeFirstLetter(String s)
  4. uncapitalizeFirstLetter(String str)
  5. uncapitalizeFirstLetter(String value)