Java Class Name Extract extractClassNameWithoutPackage(String className)

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

Description

Removes the package section from a fully qualified class name.

License

Open Source License

Declaration

public static String extractClassNameWithoutPackage(String className) 

Method Source Code

//package com.java2s;
/*//from w w w  .j ava  2 s  .  c om
 * Generator Runtime Servlet Framework
 * Copyright (C) 2004 Rick Knowles
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * Version 2 as published by the Free Software Foundation.
 *
 * 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 Public License Version 2 for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * Version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

public class Main {
    /**
     * Removes the package section from a fully qualified class name.
     */
    public static String extractClassNameWithoutPackage(String className) {
        int dotPos = className.lastIndexOf(".");
        if (dotPos != -1) {
            className = className.substring(dotPos + 1);
        }
        int dollarPos = className.lastIndexOf("$");
        if (dollarPos != -1) {
            className = className.substring(dollarPos + 1);
        }
        return className;
    }
}

Related

  1. extractClassName(String javaSource)
  2. extractClassName(String methodName)
  3. extractClassName(String qualifiedName)
  4. extractClassNameFromArray(final String arrayName)
  5. extractClassNames(Class[] classArray)
  6. extractClassNameWithParent(String fullClassName)