- Guava 教程
- Guava - 首頁
- Guava - 概述
- Guava - 環境設定
- Guava - Optional 類
- Guava - Preconditions 類
- Guava - Ordering 類
- Guava - Objects 類
- Guava - Range 類
- Guava - Throwables 類
- Guava - 集合工具類
- Guava - 快取工具類
- Guava - 字串工具類
- Guava - 原生型別工具類
- Guava - 數學工具類
- Guava 有用資源
- Guava - 快速指南
- Guava - 有用資源
- Guava - 討論
Guava - CaseFormat 類
CaseFormat 是一個工具類,用於提供各種ASCII字元格式之間的轉換。
類宣告
以下是com.google.common.base.CaseFormat類的宣告:
@GwtCompatible public enum CaseFormat extends Enum<CaseFormat>
列舉常量
| 序號 | 列舉常量及描述 |
|---|---|
| 1 | LOWER_CAMEL Java變數命名約定,例如:“lowerCamel”。 |
| 2 | LOWER_HYPHEN 帶連字元的變數命名約定,例如:“lower-hyphen”。 |
| 3 |
LOWER_UNDERSCORE C++變數命名約定,例如:“lower_underscore”。 |
| 4 |
UPPER_CAMEL Java和C++類命名約定,例如:“UpperCamel”。 |
| 5 |
UPPER_UNDERSCORE Java和C++常量命名約定,例如:“UPPER_UNDERSCORE”。 |
方法
| 序號 | 方法及描述 |
|---|---|
| 1 |
Converter<String,String> converterTo(CaseFormat targetFormat) 返回一個轉換器,用於將字串從此格式轉換為targetFormat。 |
| 2 |
String to(CaseFormat format, String str) 將指定的字串str從此格式轉換為指定的格式。 |
| 3 |
static CaseFormat valueOf(String name) 返回具有指定名稱的此型別的列舉常量。 |
| 4 |
static CaseFormat[] values() 返回一個包含此列舉型別的常量陣列,按宣告順序排列。 |
繼承的方法
此類繼承自以下類的方法:
- java.lang.Enum
- java.lang.Object
CaseFormat 類示例
使用您選擇的任何編輯器建立以下Java程式,例如在C:/> Guava目錄下。
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
guava_string_utilities.htm
廣告