Java.lang.Package.toString() Method



Description

The java.lang.Package.toString() method returns the string representation of this Package. Its value is the string "package " and the package name. If the package title is defined it is appended. If the package version is defined it is appended.

Declaration

Following is the declaration for java.lang.Package.toString() method

public String toString()

Parameters

NA

Return Value

This method returns the string representation of the package.

Exception

NA

Example

The following example shows the usage of lang.Object.toString() method.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // get the java lang package
      Package pack = Package.getPackage("java.lang");

      // print the package as a string
      System.out.println("" + pack.toString());
   }
}

Let us compile and run the above program, this will produce the following result −

package java.lang, Java Platform API Specification, version 1.8
java_lang_package.htm
Advertisements