目录

CaseFormat

CaseFormat是一个实用程序类,用于提供各种ASCII字符格式之间的转换。

Class 声明 (Class Declaration)

以下是com.google.common.base.CaseFormat类的声明 -

@GwtCompatible
public enum CaseFormat
   extends Enum<CaseFormat>

枚举常量

Sr.No 枚举常量和描述
1

LOWER_CAMEL

Java变量命名约定,例如“lowerCamel”。

2

LOWER_HYPHEN

连字符变量命名约定,例如“lower-hyphen”。

3

LOWER_UNDERSCORE

C ++变量命名约定,例如“lower_underscore”。

4

UPPER_CAMEL

Java和C ++类命名约定,例如“UpperCamel”。

5

UPPER_UNDERSCORE

Java和C ++常量命名约定,例如“UPPER_UNDERSCORE”。

方法 (Methods)

Sr.No 方法和描述
1

Converter《String,String》 converterTo(CaseFormat targetFormat)

返回一个Converter,它将字符串从此格式转换为targetFormat。

2

String to(CaseFormat format, String str)

将指定的String str从此格式转换为指定的格式。

3

static CaseFormat valueOf(String name)

返回具有指定名称的此类型的枚举常量。

4

static CaseFormat[] values()

按照声明的顺序返回一个包含此枚举类型常量的数组。

方法继承 (Methods Inherited)

该类继承以下类中的方法 -

  • java.lang.Enum
  • java.lang.Object

CaseFormat类的示例

使用您选择的任何编辑器在C:/》 Guava.创建以下java程序C:/》 Guava.

GuavaTester.java

import com.google.common.base.CaseFormat;
public class GuavaTester {
   public static void main(String args[]) {
      GuavaTester tester = new GuavaTester();
      tester.testCaseFormat();
   }
   private void testCaseFormat() {
      String data = "test_data";
      System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));
      System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));
      System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));
   }
}

验证结果

使用javac编译器编译类如下 -

C:\Guava>javac GuavaTester.java

现在运行GuavaTester来查看结果。

C:\Guava>java GuavaTester

看到结果。

testData
testData
TestData
↑回到顶部↑
WIKI教程 @2018