Explain Codes LogoExplain Codes Logo

Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse?

java
intellij-idea
code-completion
auto-import
Anton ShumikhinbyAnton Shumikhin·Jan 29, 2025
TLDR

Instantly import in IntelliJ IDEA with Alt + Enter for a single class or Ctrl + Alt + O (Windows/Linux) / ⌘ + Option + O (macOS) to optimize all imports. Amp your automation game with Add unambiguous imports on the fly and Optimize imports on the fly under Editor -> General -> Auto Import.

Supercharging import efficiency with IntelliJ IDEA

Code completion: Your secret weapon

Code completion is not just about predicting lines, it's actively resourceful, suggesting necessary imports, and adding them as you pick a suggestion. So, IntelliJ IDEA plays importer and a bodyguard by filtering out irrelevant imports.

Imports! Let's auto-mate them all

Dive into the settings under Editor -> General -> Auto Import and gear up IntelliJ IDEA to handle imports aggressively or cautiously:

  • Specific imports: Tell IntelliJ IDEA to ignore imports that you never use or those that might invite ambiguity.
  • Execute clean-ups: IntelliJ IDEA’s import optimizer doesn’t just add, it deducts unused imports, giving you the lean code you crave (and much deserved coffee breaks).
  • Set thresholds: Lower the barriers for an import to be anything but ambiguous, thus making IntelliJ IDEA more or less eager on auto-imports.

Spotting errors is no longer akin to a criminal investigation. A simple F2 lets you jump between errors, including missing imports while our friend, the quick fix (Alt + Enter) is available round the clock for patchwork. It's like having an assistant who "accidentally" solves the Rubiks Cube.

Advanced features for the power users

Embrace new levels of efficiency with these advanced features of IntelliJ IDEA's auto-import:

Eclipse Code Formatter plugin: Old school meets the new kid

Love Eclipse's import organization style? Well, Eclipse Code Formatter plugin brings that familiar behavior right into IntelliJ IDEA. Truly, best of both worlds!

Holy Import! Not just classes

IntelliJ IDEA auto-import doesn't discriminate - it auto-imports methods and static members, elegantly wrapping up your code and reducing manual import efforts.

Managing ambiguity like a pro

Those pesky duplicate class names from different packages shouldn't cause wrinkles. Exclude classes or packages causing conflicts in Editor -> General -> Auto Import -> Exclude from Import and Completion, finessing the precision of auto-imports.

Shortcuts to Superpowers

Shortcuts like Alt + Enter and Ctrl + Shift + A (remember this combination to search for any action or setting) can be your nifty time-savers. It's like having a voice-activated assistant, but for developers!