Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a string from snake case to camel case in Java

Tags:

java

string

How can I convert snake case to camel case in Java?

Input: "input_in_snake_case"

Output: "InputInSnakeCase"

like image 955
Kamesh Avatar asked Sep 05 '14 07:09

Kamesh


People also ask

Does Java use camel case or snake case?

Java uses CamelCase as a practice for writing names of methods, variables, classes, packages, and constants.


1 Answers

Guava supports this through its CaseFormat class

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

Output

InputInSnakeCase 
like image 185
Adam Avatar answered Sep 28 '22 14:09

Adam