Java - Write code to Convert camel Case To Dash with for loop

Requirements

Write code to Convert camel Case To Dash with for loop

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String value = "AbcDef";
        System.out.println(camelCaseToDash(value));
    }/*from w  ww  . jav  a  2s  .co  m*/

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

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

Related Example