Java CaseFormat类

Java CaseFormat类

CaseFormat 是一个实用类,用于在各种 ASCII 大小写格式之间进行转换。对于非ASCII格式的输入,其行为未被定义。

声明: com.google.common.base.CaseFormat的声明如下。

@GwtCompatible
public enum CaseFormat
   extends Enum
Java

下表给出了Enum常量的摘要和它们的描述:

CaseFormat类  Guava  Java

下表给出了CaseFormat类的方法和它们的描述:

CaseFormat类  Guava  Java

例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));
    }
}
Java

输出:

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

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

输出:

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

参考资料: Google Guava

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册