Java Class Simple Name Get simpleClassName(final String className)

Here you can find the source of simpleClassName(final String className)

Description

Returns the simple class name from the fully qualified class name.

License

Open Source License

Parameter

Parameter Description
className the fully qualified class name

Return

the package name

Declaration

public static String simpleClassName(final String className) 

Method Source Code

//package com.java2s;
/*//from  w ww.j  a  v a2s.  c  o m
 * StringUtils.java
 *
 * Created on October 4, 2006, 2:36 PM
 *
 * Description:
 *
 * Copyright (C) 2006 Stephen L. Reed.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation; either
 * version 2 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 Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

public class Main {
    /** Returns the simple class name from the fully qualified class name.
     *
     * @param className the fully qualified class name
     * @return the package name
     */
    public static String simpleClassName(final String className) {
        //Preconditions
        assert className != null : "className must not be null";
        assert !className.isEmpty() : "className must not be empty";

        final int index = className.lastIndexOf('.');
        assert index > -1 : "cannot find package in import " + className;
        return className.substring(index + 1);
    }
}

Related

  1. simpleClassName(Class klass)
  2. simpleClassName(Class clazz)
  3. simpleClassName(Class clazz)
  4. simpleClassName(Class clazz)
  5. simpleClassName(Class type)
  6. simpleClassName(Object o)
  7. simpleClassName(Object o)
  8. simpleClassName(Object object)
  9. simpleClassName(String fqn)