Java String Camel Case Format toCamelCase(String text)

Here you can find the source of toCamelCase(String text)

Description

Converts the string to camel case.

License

Open Source License

Parameter

Parameter Description
text a parameter

Return

string in camel case

Declaration

public static String toCamelCase(String text) 

Method Source Code

//package com.java2s;
/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net//from  w ww  .j  a v  a 2 s .c om
 * (C) 2012, Refractions Research Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD
 * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html).
 */

public class Main {
    /**
     * Converts the string to camel case.
     * 
     * @param text
     * @return string in camel case
     */
    public static String toCamelCase(String text) {
        int count = 0;
        final StringBuilder sb = new StringBuilder();
        final String[] words = text.replace('_', ' ').split(" "); //$NON-NLS-1$
        for (String word : words) {
            count++;
            if (word.length() == 1) {
                sb.append(word.toUpperCase());
            } else if (word.length() > 1) {
                sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase());
            }
            if (count < words.length) {
                sb.append(" "); //$NON-NLS-1$
            }
        }
        return sb.toString();
    }
}

Related

  1. toCamelCase(String string)
  2. toCamelCase(String string)
  3. toCamelCase(String string)
  4. toCamelCase(String string)
  5. toCamelCase(String stringValue, String delimiter)
  6. toCamelCase(String text)
  7. toCamelCase(String text)
  8. toCamelCase(String text, boolean capFirstLetter)
  9. toCamelCase(String value)