Java String Upper Case toUppercaseAndUnderscore(String string)

Here you can find the source of toUppercaseAndUnderscore(String string)

Description

to Uppercase And Underscore

License

Apache License

Declaration

public static String toUppercaseAndUnderscore(String string) 

Method Source Code

//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();
    }
}

Related

  1. toUpperCase(String value)
  2. toUpperCase(String[] header)
  3. toUpperCase(String[] list)
  4. toUpperCase(String[] source)
  5. toUpperCase(StringBuffer buf)
  6. toUpperCaseArray(String[] source, String[] target)
  7. toUpperCaseAscii(String s)
  8. toUpperCaseAt(String oldString, int index)
  9. toUpperCaseAtFirstChar(String string)