Related Articles

Related Articles

CaseFormat Class | Guava | Java
  • Last Updated : 15 Nov, 2018

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :