Java CaseFormat类
CaseFormat 是一个实用类,用于在各种 ASCII 大小写格式之间进行转换。对于非ASCII格式的输入,其行为未被定义。
声明: com.google.common.base.CaseFormat的声明如下。
@GwtCompatible
public enum CaseFormat
extends Enum
Java
下表给出了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));
}
}
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