Here you can find the source of toSnakeCase(String camelCase)
public static String toSnakeCase(String camelCase)
//package com.java2s; //License from project: Open Source License public class Main { private static final String SNAKE_CASE_SPLIT_REGEX = "(?<!^)(?<![A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"; public static String toSnakeCase(String camelCase) { if (camelCase == null) { throw new NullPointerException(); }//from w w w .j ava 2 s . c o m String[] parts = camelCase.split(SNAKE_CASE_SPLIT_REGEX); StringBuilder builder = new StringBuilder(camelCase.length() + (parts.length - 1)); for (int i = 0; i < parts.length - 1; i++) { builder.append(parts[i].toLowerCase()).append('_'); } builder.append(parts[parts.length - 1].toLowerCase()); return builder.toString(); } }