How to remove unused imports in Eclipse

Often times, after code refactor or bug fixed, Eclipse IDE will show a yellow underline for all unsed imports at the top of your class and said “The import xxx is never used“.

remove unused imports in eclipse

To remove those unused imports automatically, just click on the class and press the shortcut “Ctrl + Shift + O” to initilize the “Organize imports” feature.

Alternatively, in Eclipse IDE, select “Source” > “Organize imports

remove unused imports in eclipse

About the Author

author image
Founder of, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.


3 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
3 Comment authors
hardik NaiBalaji Boggaram Ramanarayanvasu Recent comment authors
newest oldest most voted

nice, but a project contains lot number of classes. one or more classes may have unused imports. we can remove all the unnecessary imports in a project with one click. i.e.,

select project–>right click–>source–>organise imports.

It will remove all the unused imports at a time.

so, we can do this on project level basis, package level basis or class level.

We can even keep a preference for save to remove the unused imports.

Balaji Boggaram Ramanarayan
Balaji Boggaram Ramanarayan

Nice. We can also set up our eclipse workspace with this rule always. Thats what I do 🙂

hardik Nai
hardik Nai

Nice to remove code cleanup. but i have issue to add black line in that import place.
Can you guide me how to remove blank line in between import statement?