Java String Camel Case Format toCamelCase(String text)

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

Description

Create a camel case string (eg.

License

Open Source License

Parameter

Parameter Description
text The underscore separated string

Return

The camelCase string

Declaration

public static String toCamelCase(String text) 

Method Source Code

//package com.java2s;
/**//w  w w  . j  a v  a  2  s. c  om
  * Copyright (c) 2009 University of Rochester
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the  
  * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project
  * website http://www.extensiblecatalog.org/. 
  *
  */

public class Main {
    /**
     * Create a camel case string (eg. endOfFile) from an underscore-separated 
     * compounds (eg. "end_of_file") 
     * @param text The underscore separated string
     * @return The camelCase string
     */
    public static String toCamelCase(String text) {
        if (text.indexOf('_') >= 0) {
            StringBuffer buff = new StringBuffer(text.length());
            boolean afterHyphen = false;
            for (int n = 0; n < text.length(); n++) {
                char c = text.charAt(n);
                if (c == '_') {
                    afterHyphen = true;
                } else {
                    if (afterHyphen) {
                        buff.append(Character.toUpperCase(c));
                    } else {
                        buff.append(c);
                    }
                    afterHyphen = false;
                }
            }
            text = buff.toString();
        }
        return text;
    }
}

Related

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