The statement
import java.util.ArrayList.*;
imports all nested classes of ArrayList, but not ArrayList itself. Since ArrayList does not have any (public) nested classes, the statement actually does nothing.
However, consider the interface Map
, which defines the nested class Map.Entry
. If we write
import java.util.Map.*;
at the start of the Java file, we can then write Entry<A,B>
instead of Map.Entry<A,B>
to refer to this nested class.
Importing members of classes usually makes the most sense if you are using static imports. Then you don't import nested classes, but static methods and variables. For example,
import static java.Math.*;
will import all static constants and methods from the Math
class. Then you can use the static methods of the Math
class by writing, e.g. sin(x)
instead of Math.sin(x)
.
import java.lang.Math
is redundant. You don't have to import things injava.lang
.