Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static String getPackageName(Class<?> clazz) {
        String className = clazz.getName();
        int lastIndex = className.lastIndexOf(".");
        if (lastIndex != -1) {
            return className.substring(0, lastIndex);
        } else {
            return null;
        }
    }
}