Requirements
Oh no! Some of the developers used snake_case instead of camelCase in our Java application. We created a script for renaming variable names but one part is missing – transforming actual value to camelCase format.
Can you help us with transformation?
These are requirements:
- An algorithm needs to transform the given String value from snake_case to camelCase format.
- It needs to have a method named convertToCamelCase that accepts String type as a parameter. A method needs to return transformed value.
- Words inside a given value are separated either with _ or –.
- Cases that need to be considered as well are the ones where the separator is placed at the beginning or at the end of the value.
Input:
public static void main(String[] args) {
covertToCamelCase("animal-zebra");
covertToCamelCase("this-is-animal");
covertToCamelCase("has-tail-");
covertToCamelCase("-tail-is-long-");
}
Output:
animalZebra
thisIsAnimal
hasTail
tailIsLong
Hint
The java.lang.Character class to the rescue.
Too Easy?
This was too easy for you? Try to create an algorithm that will transform camelCase format to snake_case format.
Send Us Your Solution
If you’re interested in our feedback, please send us your solution here. We’ll review it and let you know.
[contact-form-7 404 "Not Found"]