Java String Underscore to underscoreToPascalCase(final String str)

Here you can find the source of underscoreToPascalCase(final String str)

Description

underscore To Pascal Case

License

Open Source License

Declaration

public static String underscoreToPascalCase(final String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String underscoreToPascalCase(final String str) {
        return underscoreTo(str, true);
    }/*from   w  w  w . j a  va  2  s.  c  o m*/

    private static String underscoreTo(final String str, final boolean pascal) {
        final StringBuilder sb = new StringBuilder();
        boolean underscore = false;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c == '_') {
                underscore = true;
            } else {
                if (underscore || (i == 0 && pascal)) {
                    sb.append(Character.toUpperCase(c));
                } else {
                    sb.append(c);
                }
                underscore = false;
            }
        }
        return sb.toString();
    }
}

Related

  1. underscoreDashToCamelCase(String s)
  2. underscoresToCamelCaseImpl(String input, boolean capNextLetter)
  3. underscoresToSpaces(String value)
  4. underscoreToCamel(String input, boolean firstLetterUppercase)
  5. underscoreToCamelCase(String wordConstruct)
  6. underscoreToSpace(String text)
  7. underscoreToSpace(String value)