Java String Decamel Case deCamelCap(String s)

Here you can find the source of deCamelCap(String s)

Description

de Camel Cap

License

LGPL

Declaration

public static String deCamelCap(String s) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static String deCamelCap(String s) {

        if (s.length() == 0)
            return s;

        return Character.toUpperCase(s.charAt(0)) + deCamel(s.substring(1));
    }//from w ww.  j a v a2  s  . com

    public static String deCamel(String s) {

        if (s.length() < 2)
            return s;

        StringBuilder sb = new StringBuilder();
        sb.append(s.charAt(0));

        for (int i = 0; i < s.length() - 2; i++) {

            boolean[] c = new boolean[] { Character.isUpperCase(s.charAt(i)),
                    Character.isUpperCase(s.charAt(i + 1)), Character.isUpperCase(s.charAt(i + 2)) };

            if (c[1] && !(c[0] && c[2]))
                sb.append(' ');
            sb.append((c[1] && !c[2]) ? Character.toLowerCase(s.charAt(i + 1)) : s.charAt(i + 1));
        }
        return sb.append(s.charAt(s.length() - 1)).toString();
    }
}

Related

  1. decamel(String name)
  2. deCamelCase(final String original)
  3. deCamelCase(String camelCased, String delim)
  4. deCamelCase(String identifier)
  5. deCamelCaseStyle(String style)