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.
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.