當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Package getPackages()用法及代碼示例


java.lang.Package類的getPackages()方法用於獲取由調用者的類加載器定義的Packages。該方法將軟件包作為Package對象的數組返回。

用法:

public boolean getPackages(String desiredVersion)

參數:此方法不接受任何參數。


返回值:此方法將軟件包作為Package對象的數組返回。

下麵的程序演示了getPackages()方法。

範例1:

// Java program to demonstrate 
// getPackages() method 
  
public class Test { 
    public static void main(String[] args) 
    { 
  
        // get the Packages using getPackages() method 
        Package[] packages = Package.getPackages(); 
  
        // print all packages, one by one 
        for (int i = 0; i < packages.length; i++) { 
            System.out.println(packages[i]); 
        } 
    } 
}
輸出:
package sun.reflect, Java Platform API Specification, version 1.8
package java.util, Java Platform API Specification, version 1.8
package sun.reflect.annotation, Java Platform API Specification, version 1.8
package java.lang.annotation, Java Platform API Specification, version 1.8
package java.nio, Java Platform API Specification, version 1.8
package sun.nio, Java Platform API Specification, version 1.8
package java.security.cert, Java Platform API Specification, version 1.8
package java.util.zip, Java Platform API Specification, version 1.8
package sun.launcher, Java Platform API Specification, version 1.8
package sun.security.action, Java Platform API Specification, version 1.8
package java.nio.file, Java Platform API Specification, version 1.8
package java.nio.charset, Java Platform API Specification, version 1.8
package sun.net.www, Java Platform API Specification, version 1.8
package java.lang.ref, Java Platform API Specification, version 1.8
package java.net, Java Platform API Specification, version 1.8
package sun.net.www.protocol.file, Java Platform API Specification, version 1.8
package java.lang.invoke, Java Platform API Specification, version 1.8
package sun.util.locale, Java Platform API Specification, version 1.8
package sun.reflect.generics.repository, Java Platform API Specification, version 1.8
package sun.misc, Java Platform API Specification, version 1.8
package java.lang.reflect, Java Platform API Specification, version 1.8
package sun.net.util, Java Platform API Specification, version 1.8
package java.security, Java Platform API Specification, version 1.8
package sun.net.www.protocol.jar, Java Platform API Specification, version 1.8
package java.util.concurrent, Java Platform API Specification, version 1.8
package java.util.concurrent.atomic, Java Platform API Specification, version 1.8
package java.util.concurrent.locks, Java Platform API Specification, version 1.8
package sun.util, Java Platform API Specification, version 1.8
package java.lang, Java Platform API Specification, version 1.8
package java.io, Java Platform API Specification, version 1.8
package sun.reflect.misc, Java Platform API Specification, version 1.8
package sun.nio.ch, Java Platform API Specification, version 1.8
package java.util.jar, Java Platform API Specification, version 1.8
package sun.nio.cs, Java Platform API Specification, version 1.8
package java.util.function, Java Platform API Specification, version 1.8
package java.nio.charset.spi, Java Platform API Specification, version 1.8
package sun.security.util, Java Platform API Specification, version 1.8

參考: https://docs.oracle.com/javase/9/docs/api/java/lang/Package.html#getPackages-



相關用法


注:本文由純淨天空篩選整理自guptayashgupta53大神的英文原創作品 Package getPackages() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。