Java String Capitalize capitalize(final String docName)

Here you can find the source of capitalize(final String docName)

Description

Capitalize initial letters in a document name.

License

Mozilla Public License

Parameter

Parameter Description
docName Name of the document such as reference or admin-guide

Return

Capitalized name such as Reference or Admin-Guide

Declaration

private static String capitalize(final String docName) 

Method Source Code

//package com.java2s;
/*/*from   w ww.  jav  a 2  s. c o  m*/
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * If applicable, add the following below this MPL 2.0 HEADER, replacing
 * the fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *     Portions Copyright [yyyy] [name of copyright owner]
 *
 *     Copyright 2012-2013 ForgeRock AS
 *
 */

public class Main {
    /**
     * Capitalize initial letters in a document name.
     *
     * @param docName
     *            Name of the document such as reference or admin-guide
     * @return Capitalized name such as Reference or Admin-Guide
     */
    private static String capitalize(final String docName) {
        char[] chars = docName.toLowerCase().toCharArray();

        boolean isInitial = true;
        for (int i = 0; i < chars.length; i++) {
            if (isInitial && Character.isLetter(chars[i])) {
                chars[i] = Character.toUpperCase(chars[i]);
                isInitial = false;
            } else {
                isInitial = !Character.isLetter(chars[i]);
            }
        }

        return String.valueOf(chars);
    }
}

Related

  1. capitalizar(String s)
  2. capitalizarPalabra(String palabra)
  3. capitalizarTexto(String texto)
  4. capitalize(CharSequence s)
  5. capitalize(CharSequence s)
  6. capitalize(final String input)
  7. capitalize(final String name)
  8. capitalize(final String s)
  9. capitalize(final String s)