Java String Camel Case Format toCamelCase(final String init)

Here you can find the source of toCamelCase(final String init)

Description

to Camel Case

License

Apache License

Declaration

public static String toCamelCase(final String init) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toCamelCase(final String init) {
        if (init == null)
            return null;

        final StringBuilder ret = new StringBuilder(init.length());

        for (final String word : init.split("_")) {
            if (!word.isEmpty()) {
                if (word.equalsIgnoreCase("DW")) {
                    ret.append("DW");
                } else {
                    ret.append(word.substring(0, 1).toUpperCase());
                    ret.append(word.substring(1).toLowerCase());
                }//from  w ww  .j  av  a  2s  .c o  m
            }
            if (!(ret.length() == init.length()))
                ret.append("_");
        }

        return ret.toString();
    }
}

Related

  1. toCamelCase(final String identifier, boolean capital)
  2. toCamelCase(final String input, final char spacer)
  3. toCamelCase(final String inputString, boolean avoidFirst)
  4. toCamelCase(final String string)
  5. toCamelcase(final String string)