Guava之CaseFormat

com.google.common.base.CaseFormat是一种实用工具类,以提供不同的ASCII字符格式之间的转换。

枚举常量

S.N.枚举常量和说明
1LOWER_CAMEL
Java变量的命名规则,如“lowerCamel”。
2LOWER_HYPHEN
连字符连接变量的命名规则,如“lower-hyphen”。
3LOWER_UNDERSCORE
C ++变量命名规则,如“lower_underscore”。
4UPPER_CAMEL
Java和C++类的命名规则,如“UpperCamel”。
5UPPER_UNDERSCORE
Java和C++常量的命名规则,如“UPPER_UNDERSCORE”。

方法

S.N.方法及说明
1Converter<String,String> converterTo(CaseFormat targetFormat
返回一个转换,从这个格式转换targetFormat字符串。
2String to(CaseFormat format, String str)
从这一格式指定格式的指定字符串 str 转换。
3static CaseFormat valueOf(String name)
返回此类型具有指定名称的枚举常量。
4static CaseFormat[] values()
返回一个包含该枚举类型的常量数组中的顺序被声明。

继承的方法

这个类继承了以下类方法:

  • 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"));
  }
}

结果:

testData
testData
TestData
testdata
test_data
test-data

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忧郁的叮当猫

Thanks♪(・ω・)ノ

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值