駝峯下劃線連字符轉換

import com.google.common.base.CaseFormat;
import lombok.extern.slf4j.Slf4j;

/**
 * <dependency>
 * <groupId>com.google.guava</groupId>
 * <artifactId>guava</artifactId>
 * <version>23.0</version>
 * </dependency>
 *
 * @Author niewj
 * @Date 2019/12/28 15:05
 * @Version 1.0
 */
@Slf4j
public class CamelCast {
    public static void main(String[] args) {
        // "test-data"->"testData" (小寫連字符->小寫駝峯)
        log.info(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));

        //  "test_data"->"testData" (小寫下劃線->小寫駝峯)
        log.info(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));

        //  "test_data"->"TestData"  (小寫下劃線->大寫駝峯)
        log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));

        //  "testData"->"test_data" (小寫駝峯->小寫下劃線)
        log.info(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testData"));

        //  "TestData" -> "test_data" (大寫駝峯->小寫下劃線)
        log.info(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));

        //  "testData"-> "test-data" (小寫駝峯->小寫連字符)
        log.info(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));

        // "TEST_DATA"-> "testData" (大寫下劃線->小寫駝峯)
        log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "TEST_DATA"));

        // "TEST_DATA"-> test-data (大寫下劃線->小寫連字符)
        log.info(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, "TEST_DATA"));
    }
}
  • camel=駱駝
  • hyphen=連字符
  • underscore=下劃線
  • hyphen和dash區別

連字符: non-smoker 中是 hyphen
波折號: 1928-2008 中是 dashjava

相關文章
相關標籤/搜索