教程 > guava 教程 > 阅读:19

guava caseformat 类——迹忆客-ag捕鱼王app官网

返回 guava string 实用程序


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


类声明

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

@gwtcompatible
public enum caseformat
   extends enum

枚举常量

序号 常量 说明
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”。

类方法

序号 方法 说明
1 converter converterto(caseformat targetformat) 返回一个 converter,它将字符串从这种格式转换为 targetformat。
2 string to(caseformat format, string str) 将指定的字符串 str 从此格式转换为指定的格式。
3 static caseformat valueof(string name) 返回具有指定名称的此类型的枚举常量。
4 static caseformat[] values() 返回一个数组,其中包含此枚举类型的常量,按照它们声明的顺序排列。

方法继承

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

  • java.lang.enum
  • java.lang.object

caseformat 类示例

c:/> guava 中使用我们选择的任何编辑器创建以下 java 程序。

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

返回 guava string 实用程序

查看笔记

扫码一下
查看教程更方便
网站地图