How to remove unused imports in Eclipse IDE

In this article, we will discuss how to remove unused imports in Eclipse IDE

 

To remove unused imports in Eclipse IDE:

This is basically called Organize imports in Eclipse IDE. There are 2 ways; we can organize imports i.e.; removing unused imports

  1. Click Source menu –> Organize Imports
  2. Using short-cut keys CTRL + SHIFT + O

 

Option 1: Organize Imports from Source menu

Few unused imports in the below Java class

Click Source Menu –> Organize Imports

After organizing unused imports

 

Option 2: click CTRL + SHIFT + O simultaneously

Few unused imports in the below Java class

Click CTRL + SHIFT + O

 

When it is required ?

  • Initially, we thought ArrayList fits our logic to store group of similar values
  • And we started using ArrayList through-out in our program with “java.util.ArrayList” import statement right at the top of the Java class
  • But suddenly, logic changed to use HashSet instead of ArrayList for maintaining uniqueness inside Collection
  • And we started changing ArrayList to HashSet in our program
  • During these times, we would never give a look into unused imports
  • So, therefore it is better advised using this shortcut to remove unused import statement

 

References:

 

Happy Coding !!
Happy Learning !!

How to GO TO any line number directly in Eclipse IDE
How to show line numbers in Eclipse IDE