Here you can find the source of toCamelCase(final String inputString, boolean avoidFirst)
Parameter | Description |
---|---|
inputString | The string to be transformed |
avoidFirst | Define true if you want to discard the first word |
public static String toCamelCase(final String inputString, boolean avoidFirst)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. j a va 2 s . co m*/ * Replaces the white spaces and the "-" and transform the String in camel * case * * @param inputString * The string to be transformed * @param avoidFirst * Define true if you want to discard the first word * @return The transformed string in camel case */ public static String toCamelCase(final String inputString, boolean avoidFirst) { if (inputString == null) return null; final StringBuilder ret = new StringBuilder(inputString.length()); for (final String word : inputString.replaceAll("_", " ").split("[ -]")) { if (avoidFirst) { ret.append(word.toLowerCase()); avoidFirst = false; continue; } if (!word.isEmpty() && !avoidFirst) { ret.append(word.substring(0, 1).toUpperCase()); ret.append(word.substring(1).toLowerCase()); } } return ret.toString(); } }