Ctrl + Alt + O (Code → Optimize Imports…) is what you’re looking for, both on Windows/Linux and macOS keymaps.
It says “Optimize”, but, if configured to do so, it will also:
- organize existing imports
- remove unneeded imports
- add new required imports
- add unambiguous imports on the fly
You can tune the auto-import settings under “Settings → Editor → General → Auto Import” as described by Dave.
You can also modify how the imports are auto-ordered under “Settings → Editor → Code Style → Java → Imports“