Java中的CaseFormat类

Java中的CaseFormat类

CaseFormat 类是一个实用程序类,用于在各种 ASCII 大小写格式之间进行转换 -

修饰符和类型 方法和描述
对象 clone()

重写 Cloneable。

boolean equals(Object obj )

覆盖等于。

字符串。 格式(双数字)

格式的特殊化。

抽象 StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) format(double number, StringBuffer toAppendTo, FieldPosition pos) p>

格式的特殊化。

字符串 格式(长数字)

格式的特殊化。

abstract StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)格式的特殊化。

示例

现在让我们看一个实现 CaseFormat 的示例带有 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

登录后复制

以上就是Java中的CaseFormat类的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!