Hashmap <int, string> map = new hashmap <int, string> (); <br/> map. put (1, "A"); <br/> map. put (2, "B"); <br/> map. put (1, "AQ"); <br/> system. out. println (map. get (0); <br/> system. out. println (map. get (1); <br/> system. out. println (map. get (2 ));
This piece of code is interesting. You can guess the answer. The logic is okay, but the compilation won't work.
Error: syntax error on token "int", dimensions expected after this token
Cause:Reference TypeAndOriginal TypeNot clear!
Java provides two different types:Reference TypeAndOriginal Type (or built-in type).IntYesJavaThe original data type,IntegerYesJavaIsIntProvided encapsulation class.JavaEncapsulation classes are provided for each original type.
Original Type encapsulation class
Boolean
Char character
Byte byte
Short short
Int integer
Long long
Float float
Double double
The behavior of the reference type and the original type is completely different, and they have different semantics. The reference type and the original type have different features and usage, they include: size and speed problems, which type of data structure is stored, the default value specified when the reference type and original type are used as instance data of a class. The default value of the instance variables referenced by the object is null, and the default value of the original type of instance variables is related to their types.
Hashmap <integer, string> map = new hashmap <integer, string> (); <br/> map. put (1, "A"); <br/> map. put (2, "B"); <br/> map. put (1, "AQ"); <br/> system. out. println (map. get (0); <br/> system. out. println (map. get (1); <br/> system. out. println (map. get (2 ));