Why Android Studio imports the complete package on Reformatting the code

If any package is having more than N numbers of import of the same package in Android studio, it automatically converts it to * imports for that package (default are 5 for Top-level Symbols and 3 for Java Statics and Enum Members).

So, for example if you're having some N number of imports from package java.util, it gets converted to java.util.*.

Where to find that setting to change it?

  1. Open Settings from File-> Settings in Android Studio (ctrl+alt+s).

  2. Go to Editor -> Code Style -> Java/Kotlin and open imports tab then change that N number to any of your suitable case.

enter image description here

There are other options available as well.


From Intellij official documentation

When the number of classes that IntelliJ IDEA has imported from the same package reaches the limit (5 by default), the IDE modifies the statements in order to import the entire package instead of importing several single classes from this package.

You can disable this feature like following.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Code Style | Java | Imports.

  2. Make sure that the Use single class import option is enabled.

  3. In the Class count to use import with ‘*’ and Names count to use static import with ‘*’ fields, specify values that definitely exceed the number of classes in a package and the number of names in a class (for example, 999).