Why does hashmap map report an error during compilation?

Source: Internet
Author: User

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 ));

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.