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")); } } 登录后复制

C:Guava>javac GuavaTester.java登录后复制

C:Guava>java GuavaTester登录后复制