Java Field Name Get fieldNameFromPropertyName(final String propertyName)

Here you can find the source of fieldNameFromPropertyName(final String propertyName)

Description

Field names are derived from property names by lower casing the first character.

License

Open Source License

Parameter

Parameter Description
propertyName the property name

Return

a valid field name or null if property name is empty

Declaration

public static String fieldNameFromPropertyName(final String propertyName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 LegSem.//w  w w .j  a v  a2s.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     LegSem - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Field names are derived from property names by lower casing the first
     * character.
     * 
     * @param propertyName the property name
     * @return a valid field name or null if property name is empty
     */
    public static String fieldNameFromPropertyName(final String propertyName) {
        String fieldName = null;
        if (propertyName != null && propertyName.length() > 0) {
            fieldName = propertyName.substring(0, 1).toLowerCase();
            if (propertyName.length() > 1) {
                fieldName += propertyName.substring(1, propertyName.length());
            }
        }
        return fieldName;
    }
}

Related

  1. fieldName(String fieldName, String propName)
  2. fieldName(String getsetName)
  3. fieldName(String name)
  4. fieldName(String nodeName)
  5. fieldName(String underScore)
  6. fieldNameMatchesProperty(final String name, final String property)
  7. fieldNameToConstant(String fieldname)
  8. fieldNameToMethodName(String methodPrefix, String fieldName)
  9. fieldNameToPath(String fieldName)