The obvious answer is because String
is used far more often than HashMap
.
No. String
belongs to java.lang
package, which is automatically imported by the compiler.
From java.lang javadoc:
Provides classes that are fundamental to the design of the Java programming language. The most important classes are Object
, which is the root of the class hierarchy, and Class
, instances of which represent classes at run time.
And from Java Language Specification. Chapter 7. Packages
A package consists of a number of compilation units (§7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public
types declared in the predefined package java.lang
.