Here you can find the source of toUppercaseAndUnderscore(String string)
public static String toUppercaseAndUnderscore(String string)
//package com.java2s; //License from project: Apache License public class Main { public static String toUppercaseAndUnderscore(String string) { StringBuilder result = new StringBuilder(); boolean lastWasLowerCase = false; for (char i : string.toCharArray()) { if (Character.isUpperCase(i)) { if (lastWasLowerCase) { result.append("_"); }//from ww w . j a v a 2 s.c om } result.append(Character.toUpperCase(i)); lastWasLowerCase = Character.isLowerCase(i); } return result.toString(); } }