Java - Write code to uncamel - uncamelize string

Requirements

Write code to uncamel - uncamelize string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String name = "AbdDefZcy";
        System.out.println(uncamel(name));
    }//from   w  ww. j ava  2  s.  c  o  m

    /**
     * uncamel - uncamelize string
     * @param - name - original string
     * @param - delim - delimiter
     * @return camelized string
     */
    public static String uncamel(String name) {
        StringBuilder sb = new StringBuilder(name.length());
        StringBuilder last = new StringBuilder();
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if (Character.isUpperCase(ch)) {
                if (sb.length() > 0)
                    sb.append(' ');
                sb.append(last.toString());
                last.setLength(0);
            }
            last.append(Character.toLowerCase(ch));
        }
        if (sb.length() > 0)
            sb.append(' ');
        sb.append(last.toString());
        return sb.toString();
    }
}