Java String Camel Case Format toCamelCase(String s)

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

Description

For a given string, transform it in such a way that every underscore is removed, and the character following the underscore gets turned into uppercase.

License

Open Source License

Parameter

Parameter Description
s String to turn into camelCase

Declaration

private static String toCamelCase(String s) 

Method Source Code

//package com.java2s;
/* /*from w w  w .  ja va  2 s .c o m*/
 * Copyright (c) Nmote d.o.o. 2003. All rights reserved.
 * Unathorized use of this file is prohibited by law.
 * See LICENSE.txt for licensing information.
 */

public class Main {
    /**
     * For a given string, transform it in such a way that every 
     * underscore is removed, and the character following the 
     * underscore gets turned into uppercase.
     *
     * @param s String to turn into camelCase
     */
    private static String toCamelCase(String s) {
        boolean upNext = false;
        int size = s.length();
        StringBuffer result = new StringBuffer(size);
        for (int i = 0; i < size; ++i) {
            char c = s.charAt(i);
            if (c == '_') {
                upNext = true;
            } else {
                if (upNext) {
                    c = Character.toUpperCase(c);
                    upNext = false;
                }
                result.append(c);
            }
        }

        return result.toString();
    }
}

Related

  1. toCamelCase(String original)
  2. toCamelCase(String originalName)
  3. toCamelCase(String origString)
  4. toCamelCase(String s)
  5. toCamelCase(String s)
  6. toCamelCase(String s)
  7. toCamelCase(String s)
  8. toCamelCase(String s)
  9. toCamelCase(String s)