Here you can find the source of toCamelCase(String text)
Parameter | Description |
---|---|
text | The underscore separated string |
public static String toCamelCase(String text)
//package com.java2s; /**//w w w . j a v a 2 s. c om * Copyright (c) 2009 University of Rochester * * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project * website http://www.extensiblecatalog.org/. * */ public class Main { /** * Create a camel case string (eg. endOfFile) from an underscore-separated * compounds (eg. "end_of_file") * @param text The underscore separated string * @return The camelCase string */ public static String toCamelCase(String text) { if (text.indexOf('_') >= 0) { StringBuffer buff = new StringBuffer(text.length()); boolean afterHyphen = false; for (int n = 0; n < text.length(); n++) { char c = text.charAt(n); if (c == '_') { afterHyphen = true; } else { if (afterHyphen) { buff.append(Character.toUpperCase(c)); } else { buff.append(c); } afterHyphen = false; } } text = buff.toString(); } return text; } }