Here you can find the source of toCamelCase(String name)
public static String toCamelCase(String name)
//package com.java2s; /**/*from ww w.j ava 2 s. c o m*/ * LICENSING * * This software is copyright by sunkid <sunkid@iminurnetz.com> and is * distributed under a dual license: * * Non-Commercial Use: * 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/>. * * Commercial Use: * Please contact sunkid@iminurnetz.com */ public class Main { public static String toCamelCase(String name) { String[] words = constantCaseToEnglish(name).split(" "); StringBuilder s = new StringBuilder(); for (String word : words) { s.append(firstToUpper(word)); } return s.toString(); } public static String constantCaseToEnglish(String constant) { String[] words = constant.split("_"); StringBuilder english = new StringBuilder(); for (String word : words) { english.append(word.toLowerCase()); english.append(" "); } return english.substring(0, english.length() - 1); } public static String firstToUpper(String word) { if (word == null) return word; if (word.length() < 2) return word.toUpperCase(); return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); } }