Java tutorial
//package com.java2s; import java.util.Locale; public class Main { /** * @param str str * @return String */ public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; } char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); } /** * is null or its length is 0 * <p/> * <pre> * isEmpty(null) = true; * isEmpty("") = true; * isEmpty(" ") = false; * </pre> * * @param str str * @return if string is null or its size is 0, return true, else return * false. */ public static boolean isEmpty(CharSequence str) { return (str == null || str.length() == 0); } public static boolean isEmpty(String string) { return string == null || "".equals(string.trim()); } public static boolean isEmpty(String... strings) { boolean result = true; for (String string : strings) { if (isNotEmpty(string)) { result = false; break; } } return result; } /** * get length of CharSequence * <p/> * <pre> * length(null) = 0; * length(\"\") = 0; * length(\"abc\") = 3; * </pre> * * @param str str * @return if str is null or empty, return 0, else return {@link * CharSequence#length()}. */ public static int length(CharSequence str) { return str == null ? 0 : str.length(); } public static String toUpperCase(String str, int beginIndex, int endIndex) { return str.replaceFirst(str.substring(beginIndex, endIndex), str.substring(beginIndex, endIndex).toUpperCase(Locale.getDefault())); } public static boolean isNotEmpty(String string) { return !isEmpty(string); } public static boolean isNotEmpty(String... strings) { boolean result = true; for (String string : strings) { if (isEmpty(string)) { result = false; break; } } return result; } }