Java Package - toString() Method
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.
Syntax
public String toString()
Parameters
No parameter is required.
Return Value
Returns the string representation of the package.
Exception
NA.
Example:
In the example below, the java.lang.Package.toString() method is used to get the string representation of the given Package.
import java.lang.*; public class MyClass { public static void main(String[] args) { //get the java util package Package p = Package.getPackage("java.util"); //print package as string System.out.println(p.toString()); } }
The output of the above code will be:
package java.util, Java Platform API Specification, version 1.8
❮ Java.lang - Package