Visual Studio Code 中的 java 自动导入?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53534584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:50:23  来源:igfitidea点击:

java auto import in Visual Studio Code?

javavisual-studio-codeauto-import

提问by user3698042

Does VS Code have an auto-import function or hot key for Java?

VS Code 是否具有自动导入功能或 Java 热键?

I installed Java Extension Pack but I found that I need to import every libraries by myself and it is very tiring. Anybody knows solution?

我安装了Java Extension Pack,但发现每个库都需要自己导入,很累。有人知道解决方案吗?

回答by JustATech

A) in order to have everything working just like intellij or eclipse, there is an extension, install it, Ctrl+Shift+P ==> then write create java project.

A) 为了让一切都像 intellij 或 eclipse 一样工作,有一个扩展,安装它,Ctrl+Shift+P ==> 然后编写创建 java 项目。

B) now that you have the project scaffold right, just right click on the editor, choose source action, then organize imports and select the right libraries to be imported.

B) 现在您已经拥有了正确的项目脚手架,只需右键单击编辑器,选择源操作,然后组织导入并选择要导入的正确库。

回答by Davijr

For organize imports inside a java file

用于在 java 文件中组织导入

press SHIFT+ ALT + O

SHIFT+ ALT + O

The vscode has also the option of enable auto organize imports on save action

vscode 还可以选择在保存操作时启用自动组织导入

enter image description here

在此处输入图片说明