com.google.common.base.CaseFormat是一種實用工具類,以提供不同的ASCII字符格式之間的轉(zhuǎn)換。
@GwtCompatible
public enum CaseFormat
extends Enum<CaseFormat>
枚舉常量
| S.N. | 枚舉常量和說明 |
|---|---|
| 1 | LOWER_CAMEL Java變量的命名規(guī)則,如“l(fā)owerCamel”。 |
| 2 | LOWER_HYPHEN 連字符連接變量的命名規(guī)則,如“l(fā)ower-hyphen”。 |
| 3 | LOWER_UNDERSCORE C ++變量命名規(guī)則,如“l(fā)ower_underscore”。 |
| 4 | UPPER_CAMEL Java和C++類的命名規(guī)則,如“UpperCamel”。 |
| 5 | UPPER_UNDERSCORE Java和C++常量的命名規(guī)則,如“UPPER_UNDERSCORE”。 |
方法
| S.N. | 方法及說明 |
|---|---|
| 1 | Converter<String,String> converterTo(CaseFormat targetFormat 返回一個轉(zhuǎn)換,從這個格式轉(zhuǎn)換targetFormat字符串。 |
| 2 | String to(CaseFormat format, String str) 從這一格式指定格式的指定字符串 str 轉(zhuǎn)換。 |
| 3 | static CaseFormat valueOf(String name) 返回此類型具有指定名稱的枚舉常量。 |
| 4 | static CaseFormat[] values() 返回一個包含該枚舉類型的常量數(shù)組中的順序被聲明。 |
繼承的方法
這個類繼承了以下類方法:
- java.lang.Enum
- java.lang.Object
CaseFormat 示例
GuavaTester.java
import com.google.common.base.CaseFormat;
public class GuavaTester {
public static void main(String args[]) {
CaseFormatTest tester = new CaseFormatTest();
tester.testCaseFormat();
}
private void testCaseFormat() {
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"));
System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testdata"));
System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));
System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));
}
}
結(jié)果:
testData
testData
TestData
testdata
test_data
test-data