Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:48:15+00:00 2026-06-16T00:48:15+00:00

I am building a Java app that has a number of different packages. I

  • 0

I am building a Java app that has a number of different packages. I want to be able to tell programmatically which packages exist in the app that start with a specific pre-fix. Is there anyway to do this with the Java reflection APIs? I didn’t see anything like this related to the reflection apis.

Example:

com.app.controls.text
com.app.controls.picker
com.app.controls.date
etc

I want to enumerate all of these by knowing the prefix “com.app.controls” and understanding that a new package might get integrated in the future.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:48:16+00:00Added an answer on June 16, 2026 at 12:48 am

    You can do this by using Package.getPackages(), which returns an array of all packages known to the current class loader. You’ll have to manually loop through the array and find the ones with the appropriate prefix using getName().

    Here’s a quick example:

    public List<String> findPackageNamesStartingWith(String prefix) {
        return Package.getPackages().stream()
            .map(Package::getName)
            .filter(n -> n.startsWith(prefix))
            .collect(toList());
    }
    

    Note that this technique will only return the packages defined in the current class loader. If you need the packages from a different class loader, there are some options:

    1. Arrange things so that your program can run the above code from inside that class loader. This requires a certain organisation to your code base, which may or may not be feasible.

    2. Use reflection to call the (normally protected) method getPackages() on the appropriate class loader. This won’t work if the program is running under a security manager.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Java application that has parts that require daily update. I want
I am building a web app that has a class called Product, which I'd
We are building an App as shown above that has nesting of Fragments. Tabs
I have a gwt appengine app that I am building. It has a web.xml
I am building an app which looks something like this. It has a action
I'm currently building a Java app that could end up being run on many
I'm building a Java web app that needs access to a user's Google Calendar
I'm building an app on android that has the features of Log-in with facebook
I am new to Android and Java. I am building an app that allows
I'm building a Java app that loads Clojure files. I'm having trouble making a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.