How to clean up unused imports in eclipse automatically

We sometime keep unused imports in our java source and eclipse shows them using a yellow flag which I hate most. So here’s the way to clean up unused imports.

There are three ways to do that.

First one- just presses CTRL+SHIFT+O. This one is good for single source file.

Second way, how about doing it, for a whole package. Simple, go to package explorer; point your mouse on your source package, right click, find source, and then click on ‘Organize imports’. Source> Organize Imports.

And third way, how about giving this responsibility to eclipse. It will take care about removing unused imports by own. To do this, go to Windows -> Preferences -> Java -> Editor -> Save Actions and then enable Perform the selected action on save -> Organize imports.

Unused Imports  In java source code



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s