Java中的CaseFormat类

王林
王林 转载
2023-09-08 10:25:02 522浏览

Java中的CaseFormat类

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

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

重写 Cloneable。

booleanequals(Object obj )

覆盖等于。

字符串。格式(双数字)

格式的特殊化。

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

格式的特殊化。

字符串格式(长数字)

格式的特殊化。

abstract StringBufferformat(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类的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除