get Package And Class Name - Java Reflection

Java examples for Reflection:Class Name

Description

get Package And Class Name

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        Class cls = String.class;
        System.out.println(getPackageAndClassName(cls));
    }//  ww w  .j  av  a 2 s . com

    public static String getPackageAndClassName(Class<?> cls) {
        if (cls != null) {
            StringBuilder builder = new StringBuilder();
            builder.append(cls.getPackage().getName());
            builder.append(".");
            builder.append(cls.getSimpleName());
            return builder.toString();
        }
        return null;
    }
}

Related Tutorials