Here you can find the source of camelCaseToUnderscore(String camelCase)
Parameter | Description |
---|---|
camelCase | a parameter |
public static String camelCaseToUnderscore(String camelCase)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 - 2014 DigiArea, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w w w. j a v a 2s . c o m*/ * DigiArea, Inc. - initial API and implementation *******************************************************************************/ public class Main { /** * Turns CamelCased string into Underscored one * * @param camelCase * @return */ public static String camelCaseToUnderscore(String camelCase) { StringBuilder builder = new StringBuilder(); char[] chars = camelCase.toCharArray(); for (int j = 0; j < chars.length; j++) { if (Character.isUpperCase(chars[j])) { if (j != 0) { builder.append('_'); } builder.append(Character.toLowerCase(chars[j])); } else { builder.append(chars[j]); } } return builder.toString(); } }