Eclipse Ctrl + Shift + O in IntelliJ IDEA

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 :

  1. Add unambiguous imports on the fly
  2. Optimize imports on the fly
idea-organize-imports
Note
For ambiguous imports (same class name in a different package), you still need click on the class name and press ALT + ENTER keys to import the package manually.

Done.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
2 Comment threads
3 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
Erick PranataDevSimeon L.mkyongFireStarter1010 Recent comment authors
newest oldest most voted
FireStarter1010
Guest
FireStarter1010

Thank you so much, trying out idea after years in Eclipse, i was wondering WTF , i dont want to import one by one.

mkyong
Guest
mkyong

Switched to IDEA, and feel the same thing, WTF, import one by one? The option should enabled by default.

Simeon L.
Guest
Simeon L.

Useful article, totally agree – it should be a default option.

Erick Pranata
Guest
Erick Pranata

From my point of view, this should not be a default option. It causes terrible lag during refactoring…

Dev
Guest
Dev

Can you ket us know about IDEA mac shortcut key