首页  >  文章  >  Java  >  Java中的CaseFormat类

Java中的CaseFormat类

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

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类的详细内容。更多信息请关注PHP中文网其他相关文章!

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