0

What difference between

import java.util.ArrayList;
import java.util.List; //1

import java.util.*; //2

Will I import all classes from java.util in case 2 or only necessary? Is additional bytes will be added to class file in this case?

  • 1
    possible duplicate of https://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad – Jack Flamp Jan 03 '18 at 08:30
  • @JackFlamp yeah that would've been a more straightforward dupe. – Kayaman Jan 03 '18 at 08:31
  • Chek [The Java™ Tutorials's **Using Package Members** Tutorial](https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html). – cнŝdk Jan 03 '18 at 08:32

1 Answers1

4

import java.util.* will import all classes, but only the ones you actually use will be in the compiled code. It does not affect your program once it is compiled. It only makes the compilation a little bit longer (probably talking milliseconds here), but nothing we can see, so just use whichever way you prefer/ is clearer.

Bentaye
  • 9,403
  • 5
  • 32
  • 45