Here you can find the source of toCamelCase(String name)
public static StringBuilder toCamelCase(String name)
//package com.java2s; //Licensed under the Apache License, Version 2.0 (the "License"); public class Main { public static StringBuilder toCamelCase(String name) { StringBuilder buffer = new StringBuilder(); int toUpper = 0; char c;/*from w ww . ja v a2 s. c o m*/ for (int i = 0, len = name.length(); i < len;) { c = name.charAt(i++); if (c == '_') { if (i == len) break; if (buffer.length() != 0) toUpper++; continue; } else if (toUpper != 0) { if (c > 96 && c < 123) { buffer.append((char) (c - 32)); toUpper = 0; } else if (c > 64 && c < 91) { buffer.append(c); toUpper = 0; } else { while (toUpper > 0) { buffer.append('_'); toUpper--; } buffer.append(c); } } else { if (buffer.length() == 0 && c > 64 && c < 91) buffer.append((char) (c + 32)); else buffer.append(c); } } return buffer; } }