How to Add All Missing Imports Automatically in Java and Visual Studio Code

Sometimes I have to insert import statements one by one in Visual Studio Code when I develop a Java program. It’s annoying and a waste of time for me, and if you are facing the same problem, this guide will keep you away from annoying codes and manual operations from import statements.

First, open your settings dialog, like this:

Settings

Next, type java import save in search box to filter options we need.

Filtered Settings

Finally, check the option Enable/disable auto organize imports on save action, like this:

Final Settings

That’s it!

You can write your code freely without thinking about import statements, and all missing import statements can be added when you save the file. Like this:

Screenshot