Java String Sentence Case toSentenceCase(String str)

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

Description

Returns the string in sentence case.

License

Open Source License

Parameter

Parameter Description
str a parameter

Declaration

public static String toSentenceCase(String str) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (C) Devamatre Technologies 2009
 * //from   w  w  w . jav a 2 s  .c o  m
 * This code is licensed to Devamatre under one or more contributor license 
 * agreements. The reproduction, transmission or use of this code or the 
 * snippet is not permitted without prior express written consent of Devamatre. 
 * 
 * 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 and the 
 * offenders will be liable for any damages. All rights, including  but not
 * limited to rights created by patent grant or registration of a utility model 
 * or design, are reserved. Technical specifications and features are binding 
 * only insofar as they are specifically and expressly agreed upon in a written 
 * contract.
 * 
 * You may obtain a copy of the License for more details at:
 *      http://www.devamatre.com/licenses/license.txt.
 *      
 * Devamatre reserves the right to modify the technical specifications and or 
 * features without any prior notice.
 *****************************************************************************/

public class Main {
    /**
     * Returns the string in sentence case.
     * 
     * @param str
     * @return
     */
    public static String toSentenceCase(String str) {
        if (isNullOrEmpty(str)) {
            throw new NullPointerException("Invalid Parameter!, str: " + str);
        }

        return new StringBuilder().append(Character.toUpperCase(str.charAt(0))).append(str.substring(1)).toString();
    }

    /**
     * Checks whether the given string is null or empty.
     * 
     * @param str
     * @return
     */
    public static boolean isNullOrEmpty(String str) {
        return str == null || str.isEmpty();
    }
}

Related

  1. toSentenceCase(final String s)
  2. toSentenceCase(String inputString)
  3. toSentenceCase(String original)
  4. toSentenceCase(String s, char endOfLineSym)
  5. toSentenceCase(String string)