Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static String toConstantFormat(String str) {
        int n = str.length();
        List<Character> list = new ArrayList<Character>();
        char c;
        for (int i = 0; i < n; i++) {
            c = str.charAt(i);
            if (i != 0 && Character.isUpperCase(c)) {
                list.add('_');
            }
            list.add(Character.toUpperCase(c));
        }

        StringBuffer buffer = new StringBuffer();
        for (Character character : list) {
            buffer.append(character);
        }
        return buffer.toString();
    }

    public static String toUpperCase(String str) {
        return str.toUpperCase();
    }
}