0

Let's say I have below class:

package com.example;

public class Main {
public static void main(String[] args) {
    ArrayList arrayList;
    LinkedHashMap linkedHashMap;
    LinkedList linkedList;
    TreeMap treeMap;
    List list;
  }
}

How can I make IntelIJ automatically import when saving, without any additional need to press Alt+Enter for every class that was not yet imported? In this case I have to press Alt+Enter 5 times.

I understand that some classes can not be imported since there are more than one candidate ( in my Example List is present in java.util but also in java.awt), and the developer needs to pick the desired one.

But how about the classes for which there is exactly one package in the classpath ( in my example java.util is the only package in which a class named ArrayList is defined)

In Eclipse this issue can easily be handled by checking the "Organize Imports" on Save Actions(Java Editor->Save Actions)

dj_frunza
  • 1,553
  • 3
  • 17
  • 28
  • Difficulty arises when 2 or more classes have the same name. – byxor Jun 20 '17 at 10:45
  • @byxor I mentioned this in my question, but I am talking about the other cases, when there is only one class with a particular name – dj_frunza Jun 20 '17 at 10:48
  • I understand your question is about saving, but this doesn't seem possible. Please check this link for an alternative [Any way (or shortcut) to auto import the classes in IntelliJ like in Eclipse?](https://stackoverflow.com/questions/31211842/any-way-or-shortcut-to-auto-import-the-classes-in-intellij-like-in-eclipse) – byxor Jun 20 '17 at 10:49
  • Glad I helped. In fact, I'm surprised you didn't get angry at me for flagging a potential duplicate. (Have a good day, you made mine a bit better) – byxor Jun 20 '17 at 10:59
  • Have a good day as well and, thanks again, I have been searching for this for a long time – dj_frunza Jun 20 '17 at 11:04

0 Answers0