Here you can find the source of toSentenceCase(String str)
Parameter | Description |
---|---|
str | a parameter |
public static String toSentenceCase(String str)
//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(); } }