BeanUtil { public static String toUnderlineName(final String s) { if (s == null) { return null; } StringBuilder sb = new StringBuilder(); boolean upperCase = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); boolean nextUpperCase = true; if (i < (s.length() - 1)) { nextUpperCase = Character.isUpperCase(s.charAt(i + 1)); } if ((i >= 0) && Character.isUpperCase(c)) { if (!upperCase || !nextUpperCase) { if (i > 0) { sb.append(GlobalConstants.UNDERLINE); } } upperCase = true; } else { upperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }  static boolean isAbstract(final Method method); static String[] getMethodParamNames(final Class<?> clazz, final String method, final Class<?>... paramTypes); static String[] getMethodParamNames(final Method method); static String getMethodSignature(final Method method); static Set<Class<?>> getClasses(final String pk); static String toUnderlineName(final String s); static String toCamelCase(final String str); static String camelStr2underLine(final String camelStr); static String toCapitalizeCamelCase(final String str); static boolean isSimpleValueType(final Class<?> clazz); static boolean isSimpleProperty(final Class<?> clazz);  }
@Test public void toUnderlineName() { String str1 = "toUnderlineName"; String str2 = BeanUtil.toUnderlineName(str1); Assert.equals(str2, "to_underline_name", ErrorCodeDef.SYSTEM_ERROR_10001); }