Eclipse IDE – How to remove unused imports ?

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

1. 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

1.1 Organize Imports from Source menu

Few unused imports in the below Java class

Click Source Menu –> Organize Imports

After organizing unused imports

1.2 Click CTRL + SHIFT + O simultaneously

Few unused imports in the below Java class

Click CTRL + SHIFT + O

Q) 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

2. Useful Eclipse IDE shortcuts :

Related Articles:

References:

Happy Coding !!
Happy Learning !!

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