Here you can find the source of camelToSnakeCase(String string)
public static String camelToSnakeCase(String string)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww .ja va2 s.c o m * Converts a string from CamelCase to snake_case. */ public static String camelToSnakeCase(String string) { switch (string) { case "IO": return "io"; case "OS": return "os"; case "MD5": return "md5"; default: StringBuilder result = new StringBuilder(string.length()); for (char c : string.toCharArray()) { if (Character.isUpperCase(c)) { if (result.length() > 0) { result.append('_'); } result.append(Character.toLowerCase(c)); } else { result.append(c); } } return result.toString(); } } }