This question already has answers here:
What is the most elegant way to convert a hyphen separated word (e.g. “do-some-stuff”) to the lower camel-case variation (e.g. “doSomeStuff”)?

(11个答案)


6年前关闭。




如何在Java中将蛇案转换为 Camel 案?

输入:“input_in_snake_case”

输出:“InputInSnakeCase”

最佳答案

Guava通过其CaseFormat类支持此功能

import com.google.common.base.CaseFormat;


public class StackOverflow25680258 {

    public static void main(String[] args) {
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "input_in_snake_case"));
    }

}

输出量
InputInSnakeCase

07-28 06:30