Here you can find the source of toCamelCase(String text)
Parameter | Description |
---|---|
text | a parameter |
public static String toCamelCase(String text)
//package com.java2s; /* uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net//from w ww .j a v a 2 s .c om * (C) 2012, Refractions Research Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html). */ public class Main { /** * Converts the string to camel case. * * @param text * @return string in camel case */ public static String toCamelCase(String text) { int count = 0; final StringBuilder sb = new StringBuilder(); final String[] words = text.replace('_', ' ').split(" "); //$NON-NLS-1$ for (String word : words) { count++; if (word.length() == 1) { sb.append(word.toUpperCase()); } else if (word.length() > 1) { sb.append(word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()); } if (count < words.length) { sb.append(" "); //$NON-NLS-1$ } } return sb.toString(); } }