扫码一下
查看教程更方便
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 |
返回一个 converter,它将字符串从这种格式转换为 targetformat。 |
2 | string to(caseformat format, string str) | 将指定的字符串 str 从此格式转换为指定的格式。 |
3 | static caseformat valueof(string name) | 返回具有指定名称的此类型的枚举常量。 |
4 | static caseformat[] values() | 返回一个数组,其中包含此枚举类型的常量,按照它们声明的顺序排列。 |
该类继承了以下类的方法 -
在 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