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:

  1. An algorithm needs to transform the given String value from snake_case to camelCase format.
  2. It needs to have a method named convertToCamelCase that accepts String type as a parameter. A method needs to return transformed value.
  3. Words inside a given value are separated either with _ or .
  4. 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.

Testing

You can check if everything is working as expected before submitting your solution. Click on the icon to download tests.

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.

Error: Contact form not found.

By Ana Peterlić

Ana is a Java Software Engineer with over 6 years of experience in designing and developing software solutions. She loves tutoring and helping others understand Java ecosystem.