Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
vasu
11 years ago

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
10 years ago

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

hardik Nai
7 years ago

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?