驼峰下划线连字符转换

import com.google.common.base.CaseFormat;

/**
 * <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
 */
public class CamelTest {

    public static void main(String[] args) {
        // test-data ----> testData (小写连字符 --> 小写驼峰)
        System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));

        //  test_data----> testData (小写下划线 --> 小写驼峰)
        System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));

        //  test_data----> TestData  (大写下划线 --> 大写驼峰)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));

        //  testData----> test_data (小写驼峰 --> 小写下划线)
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testData"));

        //  TestData----> test_data (大写驼峰 --> 小写下划线)
        System.out.println(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));

        //  testData----> test-data (小写驼峰 --> 小写连字符)
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));

        // TEST_DATA----> testData (大写下划线 --> 小写驼峰)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "TEST_DATA"));

        // TEST_DATA----> test-data (大写下划线 --> 小写连字符)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, "TEST_DATA"));
    }
}

  • camel=骆驼
  • hyphen=连字符
  • underscore=下划线
  • hyphen和dash区别
    连字符: non-smoker 中是 hyphen
    波折号: 1928-2008 中是 dash
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文 原文下载之后的格式略有点不友好,利用简述的markdown,编辑一下.版权归原作者 PEP Index > ...
    大飞哥阅读 2,529评论 0 0
  • 在 python 中,下划线命名规则往往令初学者相当 疑惑:单下划线、双下划线、双下划线还分前后……那它们的作用与...
    纵横叹阅读 839评论 0 4
  • 为什么要更改: 作为一个程序员,尤其是编码狂,每天要输入几十次下划线,前端甚至破百次,每次输入下划线都要 shif...
    折叠幸福阅读 1,815评论 0 0
  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 4,435评论 0 5
  • 越分享越清晰,越分享越有力量 昨天儿子提议作为母亲节的礼物,愿意陪我和老公去看场电话,虽然刚上完课,有点疲...
    我和榕树阅读 377评论 1 0