How to optimize imports automatically after each save in IntelliJ IDEA

Intellij IdeaIde

Intellij Idea Problem Overview


I want to learn how can I automatically optimize imports after each save as we do Eclipse(save actions).

Intellij Idea Solutions


Solution 1 - Intellij Idea

IntelliJ IDEA offers an option to Optimize imports on the fly in Settings | Editor | General | Auto Import and Optimize imports option in the Commit Project dialog.

Solution 2 - Intellij Idea

The mentioned answer works, but there is also the Intellij "save actions" plugin available from the JetBrains plugin repository that does that (as well as other things): Intellij Save Actions Plugin.

Installation

File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'

Disclaimer

I'm the plugin developer

Solution 3 - Intellij Idea

First step:

CTRL + SHIFT + A or CMD + SHIFT + A (for mac)

Second step:

Search Optimize imports

Third step:

Switch ON the option

enter image description here

Solution 4 - Intellij Idea

In version 'Ultimate 2016.2' it is:

File > Other Settings > Default Settings > Auto Import > Optimize imports on the fly

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontalha06View Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeaAlexandre DuBreuilView Answer on Stackoverflow
Solution 3 - Intellij IdeaIsrael PeralesView Answer on Stackoverflow
Solution 4 - Intellij IdeaYounessView Answer on Stackoverflow