Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaCaseFormat Class | Guava | Java

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:




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


Output:

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

Example 2:




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


Output:

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

Reference: Google Guava

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments