Java - Write code to camelize string by separator

Requirements

Write code to camelize string by separator

Demo

//package com.book2s;
import java.util.*;

public class Main {
    public static void main(String[] argv) {
        String name = "abc def";
        System.out.println(camel(name));
    }//from ww w .  ja  va 2s.c  o  m

    /**
     * camel - camelize string
     * @param - original string
     * @return camelized string
     */
    public static String camel(String name) {
        return camel(name, " ");
    }

    /**
     * camel - camelize string
     * @param - original string
     * @param - delim - delimiter
     * @return camelized string
     */
    public static String camel(String name, String delim) {
        StringBuilder b = new StringBuilder(name.length());
        StringTokenizer t = new StringTokenizer(name, delim);
        b.append(t.nextToken());
        while (t.hasMoreTokens()) {
            String token = t.nextToken();
            b.append(token.substring(0, 1).toUpperCase()); // replace spaces with
                                                           // camelCase
            b.append(token.substring(1));
        }
        return b.toString();
    }
}

Related Exercise