Java - Write code to Convert dash To Camel Case

Requirements

Write code to Convert dash To Camel Case

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String value = "abc-def";
        System.out.println(dashToCamelCase(value));
    }//from  ww w  .  j  a va  2  s. co m

    public static String dashToCamelCase(String value) {
        StringBuilder sb = new StringBuilder(value.length());
        boolean upper = false;

        for (char c : value.toCharArray()) {
            if (c == '-') {
                upper = true;
                continue;
            }
            if (upper) {
                sb.append(Character.toUpperCase(c));
            } else {
                sb.append(c);
            }
            upper = false;
        }
        return sb.toString();
    }
}

Related Exercise