CaseFormat Class | Guava | Java

CaseFormat is a utility class for converting between various ASCII case formats. Behavior is undefined for non-ASCII input.

Declaration: The declaration for com.google.common.base.CaseFormat is as:

@GwtCompatible
public enum CaseFormat
   extends Enum

Below table gives the summary of Enum Constants and their description:

Below table gives the summary of methods of CaseFormat class and their description:

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to show implementation
// of CaseFormat Class methods
  
import com.google.common.base.CaseFormat;
  
class GFG {
  
    // Driver code
    public static void main(String args[])
    {
  
        // A string variable named str
        String str = "geeks_for_geeks";
        System.out.println("Original String: "
                           + str);
  
        // "LOWER_UNDERSCORE" is a C++ variable
        // naming convention
        System.out.println("Lower Camel Format: "
                           + CaseFormat
                                 .LOWER_UNDERSCORE
                                 .to(CaseFormat
                                         .LOWER_CAMEL,
                                     str));
        // "UPPER_UNDERSCORE" is a Java and
        // C++ constant naming convention
        System.out.println("Upper Camel Format: "
                           + CaseFormat
                                 .UPPER_UNDERSCORE
                                 .to(CaseFormat
                                         .UPPER_CAMEL,
                                     str));
    }
}

chevron_right


Output:

Original String: geeks_for_geeks
Lower Camel Format: geeksForGeeks
Upper Camel Format: GeeksForGeeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to show implementation
// of CaseFormat Class methods
  
import com.google.common.base.CaseFormat;
import java.util.*;
  
class GFG {
  
    // Driver code
    public static void main(String args[])
    {
  
        // Get the enum constants with the
        // help of values() method
        System.out.println("The Enum constants "
                           + "of CaseFormat Class are:\n"
                           + Arrays
                                 .toString(CaseFormat
                                               .values()));
    }
}

chevron_right


Output:

The Enum constants of CaseFormat Class are:
[LOWER_HYPHEN, LOWER_UNDERSCORE, LOWER_CAMEL, UPPER_CAMEL, UPPER_UNDERSCORE]

Reference: Google Guava



My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.