The CaseFormat class is a utility class for converting between various ASCII case formats −
Modifier and Type | Method and Description |
---|---|
Object | clone() Overrides Cloneable. |
boolean | equals(Object obj) Overrides equals. |
String. | format(double number) Specialization of format. |
abstract StringBuffer | format(double number, StringBuffer toAppendTo, FieldPosition pos) Specialization of format. |
String | format(long number) Specialization of format. |
abstract StringBuffer | format(long number, StringBuffer toAppendTo, FieldPosition pos) Specialization of format. |
Example
Let us now see an example to implement the CaseFormat class with 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 the GuavaTester to see the result −
C:\Guava>java GuavaTester
Output
This will produce the following output −
testData testData TestData