📜  CaseFormat 类 |番石榴 |Java

📅  最后修改于: 2022-05-13 01:54:45             🧑  作者: Mango

CaseFormat 类 |番石榴 |Java

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

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

@GwtCompatible
public enum CaseFormat
   extends Enum

下表给出了枚举常量的摘要及其描述:

下表给出了 CaseFormat 类的方法汇总及其描述:

示例 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));
    }
}
输出:
Original String: geeks_for_geeks
Lower Camel Format: geeksForGeeks
Upper Camel Format: GeeksForGeeks

示例 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()));
    }
}
输出:

参考:谷歌番石榴