Here you can find the source of toCamelCase(String input, boolean capitalizeFirsLetter)
Parameter | Description |
---|---|
input | The string to convert |
capitalizeFirsLetter | Self-explanatory |
public static String toCamelCase(String input, boolean capitalizeFirsLetter)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from www . java 2 s . c o m*/ * Converts a string to camel case, so "Get \"some\" 'big' object" becomes "getSomeObject". * @param input The string to convert * @param capitalizeFirsLetter Self-explanatory */ public static String toCamelCase(String input, boolean capitalizeFirsLetter) { if (input == null) return null; input = input.replaceAll("[^A-Za-z0-9 ]", "").trim(); StringBuilder result = new StringBuilder(input.length()); char[] chars = input.toCharArray(); for (int n = 0; n < chars.length; n++) { if (n == 0) { result.append( capitalizeFirsLetter ? Character.toUpperCase(chars[n]) : Character.toLowerCase(chars[n])); } else { if (chars[n] != ' ') result.append(chars[n]); else { while (chars[n] == ' ') n++; result.append(Character.toUpperCase(chars[n])); } } } return result.toString(); } }