-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSnakeCaseToCamelCase.java
More file actions
44 lines (34 loc) · 1.07 KB
/
Copy pathSnakeCaseToCamelCase.java
File metadata and controls
44 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package stringDemo;
public class SnakeCaseToCamelCase {
// Function to convert snake case
// to camel case
public static String snakeToCamel(String str)
{
// Convert to StringBuilder
StringBuilder builder
= new StringBuilder(str);
// Traverse the string character by
// character and remove underscore
// and capitalize next letter
for (int i = 0; i < builder.length(); i++) {
// Check char is underscore
if (builder.charAt(i) == '_') {
builder.deleteCharAt(i);
builder.replace( i, i + 1,String.valueOf(Character.toUpperCase(builder.charAt(i))));
}
}
// Return in String type
return builder.toString();
}
// Driver Code
public static void
main(String[] args)
{
// Given String
String str = "geeks_for_geeks";
// Function Call
str = snakeToCamel(str);
// Modified String
System.out.println(str);
}
}