Handling unused imports in Eclipse

The following three ways can be used to fix the unused imports in Eclipse

  1. If you have a file or two with unused imports, open the file that has unused imports and use ctrl+shift+O, this automatically organizes the imports; removes unused and adds any missing imports
  2. Avoid unused imports by enabling the organize imports option in Window -> Preferences -> Java -> Editor -> Save Actions . Once this is done eclipse removes the imports automatically when a file is savedUnusedImport_SaveAction.jpg
  3. When there are already a large number of unused imports, all of them can be fixed at once by following the below steps
  • Open the Problems window in eclipse, select all the unused imports warnings
  • Right click on them and select the Quick Fix optionImport_QuickFix.jpg
  • Above step opens Quick Fix pop-window, click finishUnusedImport_SaveAction.jpg