I find that, almost always, the most appropriate Import is at the top of the list. Under Preferences > Editor > General > Auto ImportĮdit: Using this method, when there are ambiguous imports, IntelliJ will let you know, and you can then use Alt + Enter method outlined in the answer by Wuaner I think the best solution, though not exactly the same as Eclipse/Netbeans, is to change the ‘Optimize Imports’ settings. So if you keep pressing Alt + Enter, IDEA fixes one after another until all are fixed. But it actually works for “next missing type”.
![intellij remove unused imports intellij remove unused imports](https://cdn-images-1.medium.com/max/1200/1*WmU7aM-GkD4OwF6yr8pzBA.png)
People assume it only works when you are at the particular item. So rather than interrupting my development work to add an import statement, I just type the class I want (my intention) and IDEA automatically adds the import statement for the class for me. In general, IDEA uses a “develop by intentions” concept. But in the end, I suspect you’ll find the built in IDEA features work fine once you get use to their paradigm. See its instructions for more information. It lists “emulates Eclipse’s imports optimizing” as a feature.
![intellij remove unused imports intellij remove unused imports](https://www.tutorialspoint.com/intellij_idea/images/code_inspection.jpg)
#INTELLIJ REMOVE UNUSED IMPORTS CODE#
In the following screenshot, no “StringUtils” class is imported yet.Īlternatively, type the class name and then hit Alt+ Enter or ⌥+ Enter to “Show intention actions and quick-fixes” and then select the import option.Īlthough I’ve never used it, I think the Eclipse Code Formatter third party plug-in will do what you want. For static methods, you can even just keep typing the method you want. This works the same if I was typing the name of a constructor. When I select the one I want and hit enter, IDEA will automatically add the import statement. Notice the fully qualified names to the right. Use code completion and select the particular class you want: You can also add classes and packages to exclude from auto importing to make a class you use heavily, that clashes with other classes of the same name, unambiguous.įor classes that are ambiguous (or is you prefer to have the “Add unambiguous imports on the fly” option turned off), just type the name of the class (just the name is OK, no need to fully qualify). If you enable the “Add unambiguous imports on the fly” in Settings > Editor > General > Auto Import, IntelliJ IDEA will add them as you type without the need for any shortcuts.
![intellij remove unused imports intellij remove unused imports](https://res.cloudinary.com/practicaldev/image/fetch/s--FAUGl15x--/c_imagga_scale,f_auto,fl_progressive,h_720,q_auto,w_1280/https://res.cloudinary.com/dvw7amyb4/image/upload/v1550177728/vs_code_vs_webstorm_without_border.png)
Rather it has the ability to do such as you type. Put your cursor at the interface/base class name, and press the keyboard shortcuts, IntelliJ IDEA would show all the implementations of the this interface/base class.IntelliJ IDEA does not have an action to add imports. Show interface/base class implementations
![intellij remove unused imports intellij remove unused imports](https://i.ytimg.com/vi/Cpgf7nDVWkU/hqdefault.jpg)
Put your cursor in the class and outside the methods, and Press the keyboard shortcut,just as follows:Ħ. Put your cursor at the class/method and press the keyboard shortcuts, the Intellij IDEA would show the definition of the class/method. Before do this, you should put your cursor on the class to be imported(in red color).Ĥ. This shortcut would popup a list of possible actions to be used as the following picture shows. This shortcut would popup the current method’s javadoc for you, as the picture shows(put the cursor at the submit method and press keyborad shortcut):ģ. This shortcut would remove all the unused imports from current class or interface. From this tutorial you would learn some frequently used keyboard shortcuts of Intellij IDEA for java developers.