Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.Locale;

public class Main {
    public static String dashToCamelCase(String name, boolean firstLetterUpper) {
        int currIndex = 0, dashIndex;
        StringBuilder camelName = new StringBuilder(name.length());
        if (firstLetterUpper && !name.isEmpty()) {
            camelName.append(String.valueOf(name.charAt(0)).toUpperCase(Locale.ENGLISH));
            currIndex = 1;
        }
        while (currIndex < name.length() && (dashIndex = name.indexOf('-', currIndex)) >= 0) {
            camelName.append(name.substring(currIndex, dashIndex));
            if (dashIndex + 1 < name.length()) {
                camelName.append(String.valueOf(name.charAt(dashIndex + 1)).toUpperCase(Locale.ENGLISH));
            }
            currIndex = dashIndex + 2;
        }
        if (currIndex < name.length()) {
            camelName.append(name.substring(currIndex));
        }
        return camelName.toString();
    }
}