谁能告诉我如何将snake_case中的字符串转换为:
camel_case
以驼峰式命名的字符串为:
camelCase
在 Java 中?
提前谢谢您。
最佳答案
还有 Guava 的CaseFormat提供了一个相当简洁的解决方案,允许您在驼峰案例甚至其他特定案例之间进行转换。
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "camel_case"); // returns camelCase
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "CAMEL_CASE"); // returns CamelCase
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, "camelCase"); // returns CAMEL_CASE
CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "CamelCase"); // returns camel-case
关于java - Java中从snake_case到camelCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34228942/