Here you can find the source of toCamelCase(String original)
public static String toCamelCase(String original)
//package com.java2s; /*/*from ww w .j a va 2 s .co m*/ * Copyright (C) 2007-2010 J?lio Vilmar Gesser. * Copyright (C) 2011, 2013-2016 The JavaParser Team. * * This file is part of JavaParser. * * JavaParser can be used either under the terms of * a) the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * b) the terms of the Apache License * * You should have received a copy of both licenses in LICENCE.LGPL and * LICENCE.APACHE. Please refer to those files for details. * * JavaParser 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 Lesser General Public License for more details. */ public class Main { /** * Transform a string to the camel case conversion. * <p> * For example "ABC_DEF" becomes "abcDef" */ public static String toCamelCase(String original) { StringBuilder sb = new StringBuilder(); String[] parts = original.toLowerCase().split("_"); for (int i = 0; i < parts.length; i++) { sb.append(i == 0 ? parts[i] : capitalize(parts[i])); } return sb.toString(); } private static String capitalize(String original) { if (original.length() < 1) { throw new IllegalArgumentException("This string is empty"); } else if (original.length() == 1) { return original.toUpperCase(); } else { return original.substring(0, 1).toUpperCase() + original.substring(1); } } }