Java tutorial
//package com.java2s; public class Main { private static final char ID_SEPARATOR = '_'; private static String toIdName(String fieldName) { String idName = String.valueOf(Character.toLowerCase(fieldName.charAt(1))); for (int i = 2, length = fieldName.length(); i < length; ++i) { char c = fieldName.charAt(i); if (Character.isUpperCase(c)) { idName = idName + ID_SEPARATOR + Character.toLowerCase(c); } else { idName += c; } } return idName; } }