Here you can find the source of toCamelCase(String s)
Parameter | Description |
---|---|
s | a parameter |
public static String toCamelCase(String s)
//package com.java2s; //License from project: Apache License public class Main { public static final String DEFAULT_CAMEL_CASE_SPLIT = "_"; /**// www .j a v a 2s . c o m * * @param s * @return */ public static String toCamelCase(String s) { return toCamelCase(s, DEFAULT_CAMEL_CASE_SPLIT, false); } /** * * @param s * @param capitalizeFirst * @return */ public static String toCamelCase(String s, boolean capitalizeFirst) { return toCamelCase(s, DEFAULT_CAMEL_CASE_SPLIT, capitalizeFirst); } /** * * @param s * @param regex * @return */ public static String toCamelCase(String s, String regex) { return toCamelCase(s, regex, false); } /** * * @param s * the String to format * @param regex * the regex to split the String on for camel case * @param capitalizeFirst * boolean if the first letter should be capitalized * @return a String in camel case */ public static String toCamelCase(String s, String regex, boolean capitalizeFirst) { String[] split = s.split(regex); StringBuilder sb = new StringBuilder(); for (String current : split) { String first = current.substring(0, 1); String last = current.substring(1).toLowerCase(); sb.append(capitalizeFirst ? first.toUpperCase() : first.toLowerCase()); sb.append(last); capitalizeFirst = true; } return sb.toString(); } }