Here you can find the source of toCamelCase(String s)
public static String toCamelCase(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**/* www . j a va 2 s .co m*/ * Force the first character to be lower case. If there are spaces in * the string, remove them and replace the next character with a * capitalized version of itself. */ public static String toCamelCase(String s) { String str = s.trim(); StringBuilder buffer = new StringBuilder(); boolean capitalizeNext = true; // signal to capitalize next char for (int i = 0; i < str.length(); i++) { // If there is a none-alphanumeric character, skip it and insert // the next character capitalized if (!Character.isLetterOrDigit(str.charAt(i))) { capitalizeNext = true; continue; } if (capitalizeNext) { // will capitalize the first character buffer.append(Character.toUpperCase(str.charAt(i))); capitalizeNext = false; continue; } // Otherwise, just copy buffer.append(str.charAt(i)); } return buffer.toString(); } }