Java: Auto Import Class with Intellij IDEA

2015-08-12

In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package. And the worst is you need click on the class name and press ALT + ENTER keys to import the package one by one.

Solution

The IDEA is working a bit differently, the “unambiguous imports” are imported on the fly, and you need to enable this feature manually.
File –-> Settings –-> Editor –-> General –-> Auto Import

Checked these options :

  • Add unambiguous imports on the fly
  • Optimize imports on the fly

Reference

Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse?
Intellij IDEA official Help page: Auto Import

Comments
Write a Comment