Here you can find the source of capitalize(final String docName)
Parameter | Description |
---|---|
docName | Name of the document such as reference or admin-guide |
private static String capitalize(final String docName)
//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); } }