I have a class which uses HashMap and I have imported import java.util.HashMap.
On executing reformat code -> eclipse shortcut used Cntrl+Shift+R
It reformats and convert to import java.util.*
Why android studio imports all classes if we need only one , here HashMap? Isn't it unnecessary.
The import process prompts you to migrate any library and project dependencies to Android Studio, and add the dependency declarations to the build. gradle file. For more about migrating library and project dependencies, see Create an Android library.
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.*
.
Open Settings from File-> Settings in Android Studio (ctrl+alt+s).
Go to Editor -> Code Style -> Java/Kotlin and open imports tab then change that N number to any of your suitable case.
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.
In the Settings/Preferences dialog (
Ctrl+Alt+S
), select Code Style | Java | Imports.Make sure that the Use single class import option is enabled.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With