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
mkyong
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

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

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
Guest
Balaji Boggaram Ramanarayan

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

hardik Nai
Guest
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?