Here you can find the source of toUnderScoreCase(String s)
public static String toUnderScoreCase(String s)
//package com.java2s; //License from project: Apache License public class Main { private static final char SEPARATOR = '_'; public static String toUnderScoreCase(String s) { if (s == null) { return null; }/*from w w w. j a v a 2 s .c o m*/ 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) { sb.append(SEPARATOR); } upperCase = true; } else { upperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); } }