Java examples for java.lang:String Camel Case
Convert a column name with underscores to the corresponding property name using "camel case".
import static org.mynah.oblatum.util.Constants.UNDERLINE; public class Main{ public static void main(String[] argv) throws Exception{ String name = "java2s.com"; System.out.println(convertUnderscoreNameToPropertyName(name)); }//from w ww. ja va 2s .c om /** * Convert a column name with underscores to the corresponding property name using "camel case". A name * like "customer_number" would match a "customerNumber" property name. * * @param name the column name to be converted * @return the name using "camel case" */ public static String convertUnderscoreNameToPropertyName(String name) { StringBuilder result = new StringBuilder(); boolean nextIsUpper = false; if (name != null && name.length() > 0) { for (int i = 0; i < name.length(); i++) { String s = name.substring(i, i + 1); if (s.equals(UNDERLINE)) { nextIsUpper = true; } else { if (nextIsUpper) { result.append(s.toUpperCase()); nextIsUpper = false; } else { result.append(s.toLowerCase()); } } } } return result.toString(); } }