Here you can find the source of camelCaseToUnderscored(String camelCaseName)
public static String camelCaseToUnderscored(String camelCaseName)
//package com.java2s; /*/*from w w w . ja v a 2s. co m*/ * Copyright 2014 Attila Szegedi, Daniel Dekany, Jonathan Revusky * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * A deliberately very inflexible camel case to underscored converter; it must not convert improper camel case * names to a proper underscored name. */ public static String camelCaseToUnderscored(String camelCaseName) { int i = 0; while (i < camelCaseName.length() && Character.isLowerCase(camelCaseName.charAt(i))) { i++; } if (i == camelCaseName.length()) { // No conversion needed return camelCaseName; } StringBuffer sb = new StringBuffer(); sb.append(camelCaseName.substring(0, i)); while (i < camelCaseName.length()) { final char c = camelCaseName.charAt(i); if (Character.isUpperCase(c)) { sb.append('_'); sb.append(Character.toLowerCase(c)); } else { sb.append(c); } i++; } return sb.toString(); } }