Here you can find the source of toCamelCase(String s)
public static String toCamelCase(String s)
//package com.java2s; /*/*from www. j a v a 2 s.c om*/ * Copyright 2015, Yahoo Inc. * Copyrights licensed under the Apache 2.0 License. * See the accompanying LICENSE file for terms. */ public class Main { public static String toCamelCase(String s) { String[] parts = s.split("_"); if (parts.length > 1) { return convertComponentsToCamelCaseName(parts); } else if (isAllUppercase(s)) { s = s.toLowerCase(); } return s; } private static String convertComponentsToCamelCaseName(String[] parts) { StringBuilder result = new StringBuilder(); for (String s : parts) { s = s.toLowerCase(); if (s.length() != 0) { if (result.length() == 0) { result.append(s); } else { result.append(capitalize(s)); } } } return result.toString(); } private static boolean isAllUppercase(String s) { for (int i = 0; i < s.length(); i++) { if (!Character.isUpperCase(s.charAt(i))) { return false; } } return true; } public static String capitalize(String s) { return s.substring(0, 1).toUpperCase() + s.substring(1); } }