Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String capitalize(final String str) {
        if (str.length() == 0) {
            return "";
        }

        final char[] buffer = str.toCharArray();
        buffer[0] = Character.toTitleCase(buffer[0]);

        for (int i = 1; i < buffer.length; i++) {
            if (buffer[i - 1] == ' ') {
                buffer[i] = Character.toTitleCase(buffer[i]);
            }
        }
        return new String(buffer);
    }
}