public static String StringTransformation(String str){ String result = str; if (str.contains("_")) { StringBuffer sb = new StringBuffer(); Pattern pattern = Pattern.compile("([A-Za-z\d]+)(_)?"); Matcher matcher = pattern.matcher(str); boolean smallCamel = true; while (matcher.find()) { String word = matcher.group(); sb.append(smallCamel && matcher.start() == 0 ? Character.toLowerCase(word.charAt(0)) : Character.toUpperCase(word.charAt(0))); int index = word.lastIndexOf('_'); if (index > 0) { sb.append(word.substring(1, index).toLowerCase()); } else { sb.append(word.substring(1).toLowerCase()); } } result = sb.toString(); } else { result = str.toLowerCase(); } return result; }