Here you can find the source of underscore(String str)
public static String underscore(String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String underscore(String str) { if (str == null) return null; return str.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2").replaceAll("([a-z])([A-Z])", "$1_$2") .replaceAll("-", "_").toLowerCase(); }/*from ww w . ja va2s.c o m*/ }