Here you can find the source of toUnderscoreCase(String name)
public static StringBuilder toUnderscoreCase(String name)
//package com.java2s; //Licensed under the Apache License, Version 2.0 (the "License"); public class Main { public static StringBuilder toUnderscoreCase(String name) { StringBuilder buffer = new StringBuilder(); boolean toLower = false, appendUnderscore = false; for (int i = 0, len = name.length(); i < len;) { char c = name.charAt(i++); if (c == '_') { if (i == len) break; if (buffer.length() != 0) appendUnderscore = true; continue; }/*from www . j ava 2s . c o m*/ if (appendUnderscore) buffer.append('_'); if (c > 96 && c < 123) { buffer.append(c); toLower = true; } else if (c > 64 && c < 91) { if (toLower) { // avoid duplicate underscore if (!appendUnderscore) buffer.append('_'); toLower = false; } buffer.append((char) (c + 32)); } else { buffer.append(c); toLower = false; } appendUnderscore = false; } return buffer; } }