Java String Camel Case Format toCamelCase(String stringValue, String delimiter)

Here you can find the source of toCamelCase(String stringValue, String delimiter)

Description

to Camel Case

License

Apache License

Declaration

public static String toCamelCase(String stringValue, String delimiter) 

Method Source Code

//package com.java2s;
/*//from   w w  w  .  j  a va  2  s .c  om
   Copyright 2004-2008 Strategic Gains, Inc.
       
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
       
  http://www.apache.org/licenses/LICENSE-2.0
       
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

public class Main {
    public static String toCamelCase(String stringValue, String delimiter) {
        StringBuffer result = new StringBuffer(stringValue.length());
        String[] strings = parseString(stringValue.toLowerCase(), delimiter);

        for (int i = 0; i < strings.length; ++i) {
            char[] characters = strings[i].toCharArray();

            if (characters.length > 0) {
                characters[0] = Character.toUpperCase(characters[0]);
                result.append(characters);
            }
        }

        return result.toString();
    }

    /**
     * Parse a string, via a given delimiter, into an array of strings.
     * 
     * @param string the string to parse.
     * @param delimiter a delimiter to use in parsing the string.
     * @return an array of strings.
     */
    public static String[] parseString(String string, String delimiter) {
        String delim = (delimiter.equals(".") ? "\\." : delimiter);
        String[] strings = string.split(delim);

        if (strings.length == 0 && string.length() > 0) {
            strings = new String[] { string };
        }

        return strings;
    }
}

Related

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