Java String Camel Case to Underscore camelCaseToLowerCaseUnderline(String name)

Here you can find the source of camelCaseToLowerCaseUnderline(String name)

Description

camel Case To Lower Case Underline

License

Open Source License

Declaration

public static String camelCaseToLowerCaseUnderline(String name) 

Method Source Code

//package com.java2s;
/**/*  www .  j  a va  2s . c o  m*/
 * Copyright (C) 2006 - present David Bulmore  
 * All Rights Reserved.
 *
 * This file is part of Easy Java Persistence.
 *
 * EJP is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE. See the accompanying license 
 * for more details.
 *
 * You should have received a copy of the license along with EJP; if not, 
 * go to http://www.EasierJava.com and download the latest version.
 */

public class Main {
    public static String camelCaseToLowerCaseUnderline(String name) {
        StringBuilder newName = new StringBuilder();

        for (int i = 0; i < name.length(); i++)
            if (Character.isUpperCase(name.charAt(i))) {
                if (i == 0)
                    newName.append(Character.toLowerCase(name.charAt(i)));
                else
                    newName.append("_").append(Character.toLowerCase(name.charAt(i)));
            } else
                newName.append(name.charAt(i));

        return newName.toString();
    }

    public static String toString(Object[] objects) {
        StringBuilder str = new StringBuilder();

        if (objects != null)
            for (int i = 0; i < objects.length; i++)
                str.append("[").append(objects[i]).append("]").append(i < objects.length - 1 ? ", " : "");

        return str.toString();
    }
}

Related

  1. camelCase2UnderScoreCase(String str)
  2. camelCase2UnderscoreLowercase(String name)
  3. camelCaseToUnderline(String name)
  4. camelCaseToUnderscore(final String camelCaseString)
  5. camelCaseToUnderscore(final String str)
  6. camelCaseToUnderscore(String camelCase)