Get all packages in Java

Description

The following code shows how to get all packages.

Example


//from  w w  w. j  a  v a 2s.  c  o m
public class Main {
  public static void main(String args[]) {
    Package[] pkgs = Package.getPackages();
   
    for(int i=0; i < pkgs.length; i++)
      System.out.println(
             pkgs[i].getName() + " " +
             pkgs[i].getImplementationTitle() + " " +
             pkgs[i].getImplementationVendor() + " " +
             pkgs[i].getImplementationVersion()
      );
   
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy