Java Utililty Methods String Camel Case Format

List of utility methods to do String Camel Case Format

Description

The list of methods to do String Camel Case Format are organized into topic(s).

Method

StringtoCamelCase(String value)
to Camel Case
if (isEmpty(value))
    throw new RuntimeException("expected valid string");
if (value.length() > 1)
    return Character.toUpperCase(value.charAt(0)) + value.substring(1).toLowerCase();
else
    return String.valueOf(Character.toUpperCase(value.charAt(0)));
StringtoCamelCase(String value)
to Camel Case
String[] pieces = value.split("_");
if (pieces.length == 1)
    return toUpperFirstLetter(value);
StringBuilder builder = new StringBuilder();
for (int x = 0; x < pieces.length; ++x)
    builder.append(toUpperFirstLetter(pieces[x]));
return builder.toString();
StringtoCamelCase(String value)
to Camel Case
if (!Character.isLowerCase(value.charAt(0))) {
    value = value.substring(0, 1).toLowerCase() + value.substring(1);
return value;
StringtoCamelCase(String value)
Remove spaces, make each word start with uppercase.
if (value == null)
    return null;
StringBuilder result = new StringBuilder();
for (String word : value.trim().split(" +")) {
    result.append(word.substring(0, 1).toUpperCase());
    result.append(word.substring(1));
return result.toString();
...
StringtoCamelCase(String value, String separator)
to Camel Case
StringBuilder sb = new StringBuilder();
for (String part : value.split(separator)) {
    if (part.isEmpty())
        continue;
    sb.append(part.substring(0, 1).toUpperCase());
    if (part.length() > 1)
        sb.append(part.substring(1));
return sb.toString();
StringtoCamelCaseCapitalize(String underLineName)
to Camel Case Capitalize
if (underLineName == null) {
    return null;
underLineName = toCamelCase(underLineName);
return underLineName.substring(0, 1).toUpperCase() + underLineName.substring(1);
StringtoCamelCaseIdentifier(String formStr)
Utility method to create variable or method name from string.
StringBuffer res = new StringBuffer();
formStr = formStr.replaceAll("\\{(\\d)*(\\s)*\\}", "");
String[] strArr = formStr.split("\\W");
int i = 0;
for (String str : strArr) {
    if (str.trim().length() > 0) {
        char[] stringArray = str.trim().toCharArray();
        if (i == 0)
...
StringtoCamelCaseIgnoringLastChar(String string, String delimiter, boolean upperFirst)
to Camel Case Ignoring Last Char
String trimmed = string.trim();
String[] delimited;
if (delimiter.length() > 0) {
    delimited = trimmed.split(delimiter);
} else {
    delimited = new String[1];
    delimited[0] = string;
String result = "";
for (int i = 0; i < delimited.length; i++) {
    delimited[i] = toCamelCasePresevingExisting(delimited[i]);
    if ((i == 0) & !upperFirst) {
        delimited[i] = firstLetterToLower(delimited[i]);
    } else {
        delimited[i] = firstLetterToUpper(delimited[i]);
    if ((i == delimited.length - 1) && (delimited[i].length() == 1)) {
        break;
    result += delimited[i];
return result;
StringtoCamelCasePresevingExisting(String s)
to Camel Case Preseving Existing
char[] result = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
    boolean uppercaseAllowed = (i == 0) || (Character.isLowerCase(s.charAt(i - 1)));
    result[i] = s.charAt(i);
    if (!uppercaseAllowed) {
        result[i] = Character.toLowerCase(result[i]);
return new String(result);
StringtoCamelCaseSimple(String str)
to Camel Case Simple
String firstWord = str.substring(0, 1).toUpperCase();
return firstWord + str.substring(1, str.length());