Java Utililty Methods String Camel Case To

List of utility methods to do String Camel Case To

Description

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

Method

Stringcamel2underline(String hump)
camelunderline
StringBuilder underline = new StringBuilder();
char[] chars = hump.trim().toCharArray();
for (int i = 0; i < chars.length; i++) {
    char c = chars[i];
    if (i == 0)
        underline.append(toUpperCase(c));
    else {
        if (isUpperCase(c)) {
...
Stringcamel2underline(String s)
camelunderline
char c;
int upperSize = 0;
for (int i = 0; i < s.length(); i++) {
    c = s.charAt(i);
    if (Character.isUpperCase(c)) {
        upperSize++;
if (upperSize == 0) {
    return s;
StringBuilder buf = new StringBuilder(s.length() + upperSize);
for (int i = 0; i < s.length(); i++) {
    c = s.charAt(i);
    if (Character.isUpperCase(c)) {
        buf.append('_');
        buf.append(Character.toLowerCase(c));
    } else {
        buf.append(c);
return buf.toString();
StringcamelCase2Delimiter(String name, char delimiter)
camel Case Delimiter
if (name == null || !name.matches(".*[A-Z].*") || !name.matches(".*[a-z].*"))
    return name;
String regex = "([a-zA-Z])([A-Z])";
String replacement = "$1" + delimiter + "$2";
return name.replaceAll(regex, replacement).replaceAll(regex, replacement);
StringcamelCaseIt(String mappingName, String separator)
camel Case It
String localMappingName = mappingName;
while (localMappingName.endsWith(separator)) {
    localMappingName = localMappingName.substring(0, localMappingName.length() - 1);
while (localMappingName.startsWith(separator)) {
    localMappingName = localMappingName.substring(1);
int pos = localMappingName.indexOf(separator);
...
booleancamelCaseMatch(String word, String abbr)
Perfrom a String startsWith match with support for CamelCase.
StringBuilder sb = new StringBuilder();
sb.append(word.charAt(0));
for (int i = 1; i < word.length(); i++) {
    char c = word.charAt(i);
    if (Character.isUpperCase(c)) {
        sb.append(c);
String cc = sb.toString();
if (cc.startsWith(abbr)) {
    return true;
} else {
    return word.startsWith(abbr);
StringcamelCaseNameToConstant(String camelCaseName)
camel Case Name To Constant
if (camelCaseName == null || camelCaseName.isEmpty()) {
    return camelCaseName;
return camelCaseName.replaceAll("([a-z]{1})([A-Z]{1})", "$1_$2").toUpperCase();
StringcamelCaseOrSpaceToDashed(String s)
camel Case Or Space To Dashed
String trimmed = s.replaceAll("[\\s]", "");
String dashed = trimmed.replaceAll(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])",
        "(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), "-");
dashed = dashed.replaceAll("--", "-");
return dashed.toLowerCase();
StringcamelCasePrefix(String strPrefix)
camel Case Prefix
StringBuilder sb = new StringBuilder();
for (int i = strPrefix.length() - 1; i >= 0; i--) {
    char c = strPrefix.charAt(i);
    sb.insert(0, c);
    if (i != 0 && Character.isUpperCase(c)) {
        sb.insert(0, "[^A-Z]#");
return sb.toString();
StringcamelCaseSpace(final String str)
Converts a camel cased string into a string where each upper case letter is prefixed with a space.
if (str.length() == 0) {
    throw new RuntimeException("camelCaseSpace not allowed for string length 0");
final char[] charArray = str.toCharArray();
final StringBuilder result = new StringBuilder(charArray[0] + "");
for (int i = 1; i < charArray.length; i++) {
    final char c = charArray[i];
    if (Character.isUpperCase(c)) {
...
StringcamelCaseToDash(String input)
camel Case To Dash
if (input == null)
    throw new IllegalArgumentException("camelCaseToDash argument must not be null");
return input.replaceAll("([a-z])([A-Z]+)", "$1-$2").toLowerCase();