Managing Java Import Statements
You can add import statements for Java classes in any of the following ways:
- For the whole file, by pressing Alt-Shift-F (Fix Imports) when the insertion point is in the file in the Source Editor.
- Individually, by pressing Alt-Shift-I (Fast Import) when the insertion point is in the referenced class name in your code.
- By using code completion to
insert a non-fully-qualified class name into your class. When you insert a class name in this manner, the IDE
generates the import statement for you.
- By typing a class name as part of an expression in the Source Editor and then
using the editor hints feature to have the import statement generated.
Fix Imports and Fast Import Commands
The rest of this topic details the differences between the Fix Imports and the Fast Import
command.
The Fix Imports command:
- Adds import statements that are needed by your code.
- Removes unused import statements.
- The Fix Imports command does not remove fully-qualified class names
from code and replace them with import statements.
The Fast Import command enables you to choose how you want the import handled in your code.
You can:
- Generate an import statement for the class.
- Generate an import statement for the package.
- Have the fully qualified name generated in the code.
To add a single import statement:
- In the Source Editor, move the insertion point to the name of the class that needs to be imported.
- Press Alt-Shift-I.
If the class is found, the Import Class dialog box is displayed. This contains a list of classes that match the class at the insertion point.
For example, if the class name is List, the dialog box displays java.awt.List, java.util.List, and any other class that you have defined with the name List.
- Select the class that you want to import.
- Select the radio button that corresponds to the way that you want the class to be imported.
- Click Import.
The IDE generates the import statement in your Java source file.
To add all missing import statements:
Legal Notices