maven依赖

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>21.0</version>
</dependency>

 

java样例

import org.junit.Test;

import com.google.common.base.CaseFormat;

public class GuavaTester {

    @Test
    public void test() {
        System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));//testData
        System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));//testData
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));//TestData

        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testdata"));//testdata
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));//test_data
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));//test-data

    }
}

 

参考:

java 驼峰字符和下划线字符相互转换工具类==>https://blog.csdn.net/Reminisce_man/article/details/77017554

Google Guava官方教程(中文版)==>http://ifeve.com/google-guava/

相关文章:

  • 2021-08-25
  • 2022-12-23
  • 2022-01-19
  • 2021-06-08
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-01-16
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-06-26
相关资源
相似解决方案