Java String Capitalize capitalizeClass(String className)

Here you can find the source of capitalizeClass(String className)

Description

Capitalizes a full qualified class name.

License

Open Source License

Parameter

Parameter Description
className The class name to capitalize.

Return

A capitalized representation for the given className class name.

Declaration

public static String capitalizeClass(String className) 

Method Source Code

//package com.java2s;
/*//from   ww w . j av a2  s  .c o m
 * #%L
 * Webmotion server
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 - 2015 Debux
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
 * #L%
 */

public class Main {
    /**
     * Capitalizes a full qualified class name.
     * Example:
     * <code>WebMotionUtils.capitalizeClass("org.webmotion.myclass")</code> will return 
     * <code>"org.webmotion.Myclass"</code>
     * @param className The class name to capitalize.
     * @return A capitalized representation for the given <code>className</code> class name.
     */
    public static String capitalizeClass(String className) {
        StringBuilder builder = new StringBuilder(className.length());

        // Search the class name in package
        int packageIndex = className.lastIndexOf(".");
        if (packageIndex != -1) {
            builder.append(className.substring(0, packageIndex + 1));
        }

        builder.append(Character.toUpperCase(className.charAt(packageIndex + 1)));
        builder.append(className.substring(packageIndex + 2));

        className = builder.toString();
        return className;
    }
}

Related

  1. capitalize(String word)
  2. capitalize(String word)
  3. capitalize(String words)
  4. capitalize(StringBuilder text)
  5. capitalizeAt(StringBuilder builder, int index)
  6. capitalized(String s)
  7. capitalized(String s)
  8. capitalized(String str)
  9. capitalizeD(String str, char[] delimiters)