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:

Answer from Robin on Stack Overflow
🌐
DZone
dzone.com › coding › frameworks › organize imports in eclipse
Organize Imports in Eclipse
August 28, 2012 - 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.
🌐
Eclipse
help.eclipse.org › latest › topic › org.eclipse.jdt.doc.user › gettingStarted › qs-OrganizeImports.htm
Organizing import statements
Delete the import declarations ... warnings in the vertical ruler since the types used in the method are no longer imported. From the context menu in the editor, select Source > Organize Imports....
🌐
Stanford Graphics
graphics.stanford.edu › ~katokop1 › eclipse.html
Ten Things Everybody Should Try in Eclipse
Organize imports. Don't write an import statement anymore. Just use Ctrl-Shift-O (Source/Organize Imports) to update the import statements automatically. Missing imports will be added (with help from you if there are ambiguities); unneeded imports are deleted.
🌐
Eclipse
help.eclipse.org › latest › topic › org.eclipse.jdt.doc.user › reference › preferences › java › codestyle › ref-preferences-organize-imports.htm
Organize Imports Preferences
The Java > Code Style > Organize Imports preference page defines how the Organize Imports command generates the import statements in a compilation unit.
🌐
GitHub
github.com › jcs-elpa › organize-imports-java
GitHub - jcs-elpa/organize-imports-java: Automatically organize imports in Java code. · GitHub
Organize Imports Java is an Emacs plugin that helps add required imports and removes unused imports from .java file. The idea came from amazing IDE Eclipse's C-S-o key.
Starred by 14 users
Forked by 5 users
Languages   Emacs Lisp 98.8% | Makefile 1.2%
Find elsewhere
🌐
Eclipse On E
eclipseonetips.com › 2014 › 01 › 14 › essential-tools-to-manage-import-statements-in-eclipse
Essential tools to manage import statements in Eclipse | Eclipse On E
February 10, 2017 - By default, Eclipse imports classes individually but you can tell it to always convert them into wildcards: Go to Window > Preferences > Java > Code Style > Organize Imports.
🌐
Drew University
users.drew.edu › bburd › JavaForDummies6 › OrganizeImports.pdf pdf
1 Dealing with Imports
That’s how Eclipse’s Import actions work. You can ignore everything having · to do with imports until the very last minute. Then choose Source-->Organize
🌐
Linuxtopia
linuxtopia.org › online_books › eclipse_documentation › eclipse_java_development_guide › topic › org.eclipse.jdt.doc.user › reference › preferences › java › codestyle › eclipse_java_ref-preferences-organize-imports.htm
Eclipse Java Development (Galileo) - Organize Imports Preferences
The Java > Code Style > Organize Imports preference page defines how the Organize Imports command generates the import statements in a compilation unit · This list of prefixes shows the sequential order for packages imported into a Java compilation unit. Each entry defines a block.
🌐
DevOps.dev
blog.devops.dev › eclipse-shortcut-to-get-rid-of-all-unused-imports-in-a-java-file-86b9ca0085b2
How to remove of all unused Imports from a Java file in Eclipse IDE? | by javinpaul | DevOps.dev
February 22, 2024 - 1. Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from ...
🌐
Reddit
reddit.com › r/javahelp › my eclipse doesn't offer to me to import, why?
r/javahelp on Reddit: My Eclipse doesn't offer to me to import, Why?
June 5, 2023 -

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

Top answer
1 of 3
2
Your Eclipse is not configured to automatically add imports. You can do this manually by pressing Ctrl + Shift + O (Or right-click in your file and choose Source > Organize Imports). You can turn on automatic imports on file save through Window > Preferences > Java > Editor > Save Actions > Organize Imports
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
YouTube
youtube.com › profgustin
Organizing Imports in Eclipse - YouTube
Demonstrates how to add imports to your programs in Eclipse.
Published   January 16, 2012
Views   1K
🌐
Jsparrow
jsparrow.github.io › rules › organize-imports.html
Organize Imports | jSparrow Documentation
import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.apache.commons.lang3.StringUtils; public class OrganiseImportsRule { public String a(String s) { return StringUtils.upperCase(s, Locale.CANADA_FRENCH); } public String b(String s) { List<String> list = new ArrayList<>(); list.add(s); return list.get(list.indexOf(s)); } } You can auto refactor this with jSparrow. Drop this button to your Eclipse IDE workspace to install jSparrow for free:
🌐
Mkyong
mkyong.com › home › eclipse › how to import class automatically in eclipse
How to import class automatically in Eclipse - Mkyong.com
August 29, 2012 - To import above classes automatically, you can select “Source” > “Organize Imports” or press shortcut “Ctrl + Shift + O“. See result :
🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 296552
Eclipse Community Forums: Plugin Development Environment (PDE) » how to organize imports via command | The Eclipse Foundation
February 22, 2012 - The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
🌐
CodingTechRoom
codingtechroom.com › question › automatically-organize-imports-eclipse
How Can I Automatically Organize Imports in Eclipse? - CodingTechRoom
Missing imports can lead to compilation errors. Enable the 'Organize Imports' feature on file save to automate the process.
🌐
Mkyong
mkyong.com › home › intellij › eclipse ctrl + shift + o in intellij idea
Eclipse Ctrl + Shift + O in IntelliJ IDEA - Mkyong.com
January 22, 2017 - In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.