59

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

Vijay Kumar
  • 841
  • 1
  • 9
  • 13

6 Answers6

60

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

technocrat
  • 3,513
  • 5
  • 25
  • 39
Tracy Snell
  • 1,278
  • 10
  • 8
  • Thanks you, this worked, in the past I tried this but the settings didn't stick when I created a new project. I will create a few new projects and see how the setting stays across projects. – Vijay Kumar Oct 07 '14 at 14:47
  • 3
    NOTE: Also make sure to set "Class count to use import with *" to a high number as shown in the screenshot by Tracy Snell. Also see this http://stackoverflow.com/questions/3348816/intellij-never-use-wildcard-imports/25916603#25916603 – Vijay Kumar Oct 10 '14 at 16:58
  • 1
    Is there really no way to tell Intellij 15 never to use starred imports? I mean without specifying a class count??! – Stephen Hartley Feb 08 '16 at 15:07
26

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.

BevynQ
  • 8,089
  • 4
  • 25
  • 37
13

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

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
basee
  • 131
  • 1
  • 4
1

If you want to see all the specific imports without using fully qualified class names, you can do this:

go to Settings -> Code Style -> Java -> Set "class count to use import with '*': " to 100 (or any big number)

motodev
  • 13
  • 5
0

Please check if you have autoimport cancel autoimport auto-import settings under "Settings → Editor → Auto Import

Jin Thakur
  • 2,711
  • 18
  • 15
-1

I had the same issue. But the following process fixed my problem.

Press key combination ctrl+alt+O, then only the needed packages will be added.

Rao
  • 20,781
  • 11
  • 57
  • 77
Dinusha
  • 1
  • 1