Java examples for java.lang:String Camel Case
(branch_no -> branchNo )
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String inputString = "java2s.com"; System.out.println(toCamelCaseString(inputString)); }//from w w w . j a va 2s. co m public static String toCamelCaseString(String inputString) { return toCamelCaseString(inputString, false); } public static String toCamelCaseString(String inputString, boolean firstCharacterUppercase) { if (inputString == null) return null; StringBuilder sb = new StringBuilder(); boolean nextUpperCase = false; for (int i = 0; i < inputString.length(); i++) { char c = inputString.charAt(i); switch (c) { case '_': case '-': case '@': case '$': case '#': case ' ': case '/': case '&': if (sb.length() > 0) { nextUpperCase = true; } break; default: if (nextUpperCase) { sb.append(Character.toUpperCase(c)); nextUpperCase = false; } else { sb.append(Character.toLowerCase(c)); } break; } } if (firstCharacterUppercase) { sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); } return sb.toString(); } }