Class CaseUtils


  • public final class CaseUtils
    extends java.lang.Object
    Provides support for camelCase, snake_case, and other kinds of case conversions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String snakeToCamelCase​(java.lang.String str)
      Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a titlecase character and then a series of lowercase characters.
      static java.lang.String snakeToPascalCase​(java.lang.String str)
      Converts all words separated by "_" into PascalCase, that is each word is made up of a titlecase character and then a series of lowercase characters.
      static java.lang.String toCamelCase​(java.lang.String str)
      Converts all words separated by " ", "-", and "_" to CamelCase.
      static java.lang.String toCamelCase​(java.lang.String str, boolean capitalizeFirstLetter, char... delimiters)
      Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a titlecase character and then a series of lowercase characters.
      static java.lang.String toPascalCase​(java.lang.String str)
      Converts all words separated by " ", "-", and "_" to CamelCase.
      static java.lang.String toSnakeCase​(java.lang.String word)
      Convert a given word to snake_case with all lowercase letters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • snakeToPascalCase

        public static java.lang.String snakeToPascalCase​(java.lang.String str)

        Converts all words separated by "_" into PascalCase, that is each word is made up of a titlecase character and then a series of lowercase characters.

        PacalCase is just like CamelCase, except the first character is an uppercase letter.

        Parameters:
        str - the String to be converted to PascalCase, may be null
        Returns:
        camelCase of String, null if null String input
      • snakeToCamelCase

        public static java.lang.String snakeToCamelCase​(java.lang.String str)

        Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a titlecase character and then a series of lowercase characters.

        The first character is always converted to lowercase.

        Parameters:
        str - the String to be converted to camelCase, may be null
        Returns:
        camelCase of String, null if null String input
      • toCamelCase

        public static java.lang.String toCamelCase​(java.lang.String str)

        Converts all words separated by " ", "-", and "_" to CamelCase.

        The first character is always converted to lowercase.

        Parameters:
        str - the String to be converted to camelCase, may be null
        Returns:
        camelCase of String, null if null String input
      • toPascalCase

        public static java.lang.String toPascalCase​(java.lang.String str)

        Converts all words separated by " ", "-", and "_" to CamelCase.

        PacalCase is just like CamelCase, except the first character is an uppercase letter.

        Parameters:
        str - the String to be converted to PascalCase, may be null
        Returns:
        camelCase of String, null if null String input
      • toCamelCase

        public static java.lang.String toCamelCase​(java.lang.String str,
                                                   boolean capitalizeFirstLetter,
                                                   char... delimiters)

        Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a titlecase character and then a series of lowercase characters.

        The delimiters represent a set of characters understood to separate words. The first non-delimiter character after a delimiter will be capitalized. The first String character may or may not be capitalized and it's determined by the user input for capitalizeFirstLetter variable.

        A null input String returns null. Capitalization uses the Unicode title case, normally equivalent to upper case and cannot perform locale-sensitive mappings.

         CaseUtils.toCamelCase(null, false)                                 = null
         CaseUtils.toCamelCase("", false, *)                                = ""
         CaseUtils.toCamelCase(*, false, null)                              = *
         CaseUtils.toCamelCase(*, true, new char[0])                        = *
         CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'})     = "toCamelCase"
         CaseUtils.toCamelCase(" to @ Camel case", true, new char[]{'@'})   = "ToCamelCase"
         CaseUtils.toCamelCase(" @to @ Camel case", false, new char[]{'@'}) = "toCamelCase"
         
        Parameters:
        str - the String to be converted to camelCase, may be null
        capitalizeFirstLetter - boolean that determines if the first character of first word should be title case.
        delimiters - set of characters to determine capitalization, null and/or empty array means whitespace
        Returns:
        camelCase of String, null if null String input
        See Also:
        Source
      • toSnakeCase

        public static java.lang.String toSnakeCase​(java.lang.String word)
        Convert a given word to snake_case with all lowercase letters.

        This method was based on Elephant Bird's underscore method. "-", " ", "\n", "\t", "\r" are replaced with "_".

        Note: this method does not sanitize the string for use as a snake_case variable in any specific programming language.

        Parameters:
        word - The word to convert.
        Returns:
        The underscored version of the word
        See Also:
        Elephant bird