import module java.base explained
One import line instead of a wall of java.util and java.util.stream imports.
import module java.base;
public class ModuleImport {
public static void main(String[] args) {
List<String> words = List.of("record", "sealed", "scoped");
Map<String, Integer> lengths = new TreeMap<>();
for (String w : words) {
lengths.put(w, w.length());
}
System.out.println(lengths);
System.out.println(words.stream().map(String::toUpperCase).collect(Collectors.joining(", ")));
}
} Run with JDK 25: java ModuleImport.java
import module java.base; imports every public top-level class and interface from the packages that module exports. List, Map, TreeMap, Collectors and many more are available without separate import lines.
Output
{record=6, scoped=6, sealed=6}
RECORD, SEALED, SCOPED
Watch out for
- Name clashes: if two imported modules export the same simple name, the compiler reports an ambiguity and you add a normal single-type import to resolve it.
- Readers of your code lose the explicit list of what a file depends on. In application code, that trade-off is yours to make.