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 967
清歌不尽
清歌不尽 2020-11-28 07:16

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\") in Java?

11条回答
  •  被撕碎了的回忆
    2020-11-28 07:47

    Use CaseFormat from Guava:

    import static com.google.common.base.CaseFormat.*;
    
    String result = LOWER_HYPHEN.to(LOWER_CAMEL, "do-some-stuff");
    

提交回复
热议问题