Java – How to remove unused imports in Intellij IDEA on commit

automationimportintellij-ideajava

Is there a way to remove unused imports in Intellij IDEA on commit?

It is not very optimal to do it manually, CTRL + ALT + O helps but it's still manual.

Best Answer

If you are using IntelliJ IDEA or Android Studio:

Android optimize imports

Go to Settings > Editor > General >Auto Import and check the Optimize imports on the fly checkbox.