Home  >  Article  >  Java  >  CaseFormat class in Java

CaseFormat class in Java

王林
王林forward
2023-09-08 10:25:02876browse

CaseFormat class in Java

The CaseFormat class is a utility class for converting between various ASCII case formats -

##Abstract StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition pos)format(double number, StringBuffer toAppendTo , Specialization of FieldPosition pos)StringFormat (long number)Specialization of the abstract StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition pos)
Modification Symbol and type Method and description
Object clone()

Override Cloneable.

boolean equals(Object obj)

Override equals.

String. Format (Double Number)

Specialization of format.

p> format.

format.

Specialization of the format.

Example

Now let us see an example of a class that implements CaseFormat with the java file 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"));
   }
}

Compile the class using javac compiler as follows-

C:\Guava>javac GuavaTester.java

Now run GuavaTester to see the results-

C:\Guava>java GuavaTester

Output

This will produce the following output-

testData
testData
TestData

The above is the detailed content of CaseFormat class in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete