title: Getting list of fully qualified names from a simple name
body: <p>I would like to get a list of classes that are available at runtime and that match a simple name.</p>
  
  <p>For example:</p>
  
  <pre><code>public List&lt;String&gt; getFQNs(String simpleName) {
      ...
  }
  
  // Would return ["java.awt.List","java.util.List"]
  List&lt;String&gt; fqns = getFQNs("List")
  </code></pre>
  
  <p>Is there a library that would do this efficiently, or do I have to manually go through all classes in each classloader? What would be the correct way of doing that?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>One responder asked me why I wanted to do this. Essentially, I want to implement a feature that is similar to "organize imports/auto import", but available at runtime. I don't mind if the solution is relatively slow (especially if I can then build a cache so subsequent queries become faster) and <strong>if it is a best-effort</strong> only. For example, I don't mind if I do not get dynamically generated classes.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I had to devise my own solution (see below): it uses some hints provided by the other responders, but I came to realize that it needs to be extensible to handle various environments. It is not possible to automatically traverse all classloaders at runtime so you have to rely on general and domain-specific strategies to get a useful list of classes.</p>