Java String Camel Case Format toCamelCase(String str)

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

Description

to Camel Case

License

Open Source License

Declaration

public static String toCamelCase(String str) 

Method Source Code

//package com.java2s;
/*/*  www  .ja  v a  2 s. c  o m*/
 * Syncany, www.syncany.org
 * Copyright (C) 2011 Philipp C. Heckel <philipp.heckel@gmail.com> 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String toCamelCase(String str) {
        StringBuilder sb = new StringBuilder();

        for (String s : str.split("_")) {
            sb.append(Character.toUpperCase(s.charAt(0)));

            if (s.length() > 1) {
                sb.append(s.substring(1, s.length()).toLowerCase());
            }
        }

        return sb.toString();
    }
}

Related

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