Here you can find the source of toCamelCase(String id)
Parameter | Description |
---|---|
id | The id to convert |
public static String toCamelCase(String id)
//package com.java2s; public class Main { /**//from w w w . j a v a2s. c o m * Convert an identifier into CamelCase, by capitalizing the first letter * and the letter following all underscores, and then removing all * underscores. For example, "query_string" becomes "QueryString". * * @param id * The id to convert * @return The CamelCase version of the input parameter. */ public static String toCamelCase(String id) { int N = id.length(); StringBuilder sb = new StringBuilder(2 * N); boolean makeUpper = true; for (int i = 0; i < N; i++) { char ch = id.charAt(i); if (ch == '_') { makeUpper = true; } else { if (makeUpper) { ch = Character.toUpperCase(ch); makeUpper = false; } sb.append(ch); } } return sb.toString(); } }