+ 2
Should i use "*" instead of "Scanner" in "import java.util."
what is the best and efficient way to use java.util & other syntax.
5 Respuestas
+ 8
It really doesn't matter. It is not really imported, the import only shows the compiler where to search for the class. More like a reference.
+ 4
No, there isn't any difference.
+ 4
Using "Scanner" only imports the Scanner class from Java.util where "*" imports all classes in Java.util.
Therefore, if you only want the Scanner class use Scanner as this prevents the compliler importing all of "util". However, if you want to import multiple classes from "util" use "*" to reduce boilerplate code.
+ 3
If you are only using scanner and nothing else don't use *.(it imports all of the utilities)
It might not make a difference if you have a small programm but if it's big it might.
An analogy as an example:
If you only need a hammer to do something, you won't carry all of your tools with you.
0
will it make my code more efficient & better if i use the "*" although i just use one Scanner.