Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop wildcard Java package imports in IntelliJ

On IntelliJ Java IDE when I import a class using the keyboard shortcut or take the suggested import, IntelliJ imports the whole package, e.g.

public static void main(String[] args) {

  List list = new LinkedList();

} 

would result in this import line

java.util.*;

I prefer the IDE to not do a package level import and import explicit classes. I want to set this at the global level, so I don't have to deal with this at each project. Is there any way to do this?

I am on IntelliJ 13.0.2 on Mac OS X 10.8.5

Thanks

like image 290
Vijay Kumar Avatar asked Oct 06 '14 22:10

Vijay Kumar


3 Answers

Open up preferences and search for "import". This will narrow down the list you need to look through. The screen shot shows the options for when to use single imports vs * (you can see I don't like star imports).

enter image description here

like image 72
Tracy Snell Avatar answered Oct 16 '22 14:10

Tracy Snell


under File menu

select Settings (ctrl+alt+s)

select Code Style

select Java

select Imports tab

under General the check box Use single class import will determine whether packages or classes will be imported.

the Use fully qualified class names check box will not use imports rather it will insert full class names directly into the code.

like image 29
BevynQ Avatar answered Oct 16 '22 15:10

BevynQ


IntelliJ version 2020.2.3 (October built)

Preferences > Editor > CodeStyle > Java in the "General" tab check "Use Single Class import" check "Use fully qualified class names"

enter image description here

like image 31
basee Avatar answered Oct 16 '22 14:10

basee