Preferences->Java->Editor->Save Actions->Configure...
You can configure the removal of unused imports when saving from the Unnecessary Code tab.
Adding imports would normally be done as you are writing the code otherwise it won't compile.
This is how it looks like: 
Videos
Preferences->Java->Editor->Save Actions->Configure...
You can configure the removal of unused imports when saving from the Unnecessary Code tab.
Adding imports would normally be done as you are writing the code otherwise it won't compile.
This is how it looks like: 
Doing while saving is great, but if you already have lots of files that need it applied to you can also select the package in the Package Explorer and go to Source->Organise Imports It will apply to each file below that package.
You may be doing this already, I just wanted to make it clear that it can be applied to many files as can Source->Format.
Select the project in the package explorer and press Ctrl + Shift + O (same keystroke as the single class version). Should work for packages, etc.
You can edit the clean up options on save to make it organize imports. That way all of your imports will always be organized.
In eclipse 3.4 just go into Window - Preferences. In the tree view look under Java -- Editor -- Save Actions.
This is how I keep my imports organized all of the time.
I am working in Eclipse IDE. I installed it yesterday.
I have JDK 20, my project has JRE 17. (I can choose versions 18-19)
My problem and question.
When I write for example the following code:
public class t1 {
public static void main(String\[\] args) {
List<String> list = new ArrayList<String>();
}
}I am getting an error on line 3: The list cannot be converted to a type that
I know of and I can import java.util.List; But eclipse doesn't offer to me to do it. Why?Please help me
To enable this, go to Windows -> Preferences -> Java -> Editor -> Save Actions and then enable Perform the selected action on save -> Organize imports. After this, whenever you save a java file, eclipse will remove the unused imports automatically.
Little googling might help
To fix this issue:
Go to Preferences -> General -> Keys Click on Filters... and de-select Filter uncategorized commands then Ok.
Then look for the command Go To Symbol in File and select it. Then click on Unbind and then Apply and Close
Ctrl+Shift+O. should now work.
Note:
Also unbind any other conflicting commands and leave only one command for Ctrl+Shift+O and set the When to Editing Java Source.