Now there are two kinds of knowledge :

1)

Map<String, String> hashMap = new HashMap<String, String>(){
            {
            put("A", "a");
            put("B", "b");
            }            
};

2) Use static initialization blocks

Map<String, String> hashMap = new HashMap<String, String>();

static{

hashMap.put("A", "a");

hashMap.("B", "b");

}

Make a record .

hashmap How to initialize more related articles

  1. HashMap The initialization , What has been done in the end ?

    HashMap The initialization , What has been done in the end ? HashMap What are the initialization parameters ? How much is the default ? Why is it recommended to initialize the set capacity ? tableSizeFor What is the way to do ? How to get a key Of hash value ? And calculation ...

  2. hashmap Why is the initialization capacity 2 Power square

    Personal understanding Make a record , I hope you can give me your advice if you are wrong This is a hashmap When initializing capacity How to deal with the size of the capacity , Ensure that the initialization capacity is the nearest 2 Power square (JDK1.8) static final int tableSize ...

  3. hashMap Why is the initialization capacity 2 Power of power

    original text https://blog.csdn.net/sd_csdn_scy/article/details/57083619hashMap Source code to get the location of the element : static int indexFor(i ...

  4. About HashMap Initialization capacity problem

    After scanning with the Alibaba cloud code specification plug-in, the following prompt appears : hashmap should set a size when initalizing, namely hashmap You should set a size at initialization time I found an explanation on the Internet (htt ...

  5. java in hashmap Initialization of capacity

    HashMap Use HashMap(int initialCapacity) Initialize the collection . By default ,HashMap Is the capacity of the 16. But if the user specifies a number as the capacity through the constructor , that Hash Meeting ...

  6. About HashMap Initialization of capacity , There's so much learning .

    stay <HashMap The concepts that we can 't tell apart > In the article , We introduced HashMap Some concepts related to capacity , A brief introduction HashMap Capacity expansion mechanism of . We mentioned that , By default HashMap Is the capacity of the ...

  7. Alibaba Java The development manual suggests creating HashMap Set the initialization capacity , But how much is appropriate ?

    A set is Java Often used in daily development , And as a typical K-V Data structure of structure ,HashMap about Java Developers must be familiar with . About HashMap, Many people have some basic knowledge of him , Like him and hashtab ...

  8. HashMap The initialization size should be set when the collection is initialized

    In Alibaba development specification , It is recommended that the user initialize HashMap when , Collection initial size should be specified . One . reason Don't think about it , It must be about efficiency , Then why does it cause efficiency problems ? When we new One HashMap There is no initialization of its capacity ...

  9. JAVA Source code analysis -HashMap Source code analysis ( One )

    all the time ,HashMap Namely Java Frequent visitors during the interview , No matter who just graduated , Or a classmate who has worked for many years , stay Java During the interview , I'm often asked HashMap Related questions , And every time I was asked some questions that I didn't pay attention to ...

Random recommendation

  1. js node document html css Form node operations

    js node document html css Form node operations Node operation : visit . attribute . establish (1) Access to nodes :firstChild.lastChild.childNodes.parentChild( Father and son ...

  2. Cocos2d-x Development v3.2 Create a new project and add library files

    One . Add other class libraries     3.0 The above design has strong coupling , Modules in a project often exist in the form of libraries , You need to always add a link library . stay 3.0 It is often used in CocoStudio Editor resource data , So you need to add CocoStudio library . 1.1 ...

  3. Excel How to find data with duplicate names

    originate :http://jingyan.baidu.com/article/414eccf6091ff86b431f0aec.html Cokery Today, I encountered a problem in helping my colleagues sort out the data , Is in the Ex ...

  4. C# Custom message in , And MFc contrast

    stay C# The event driven approach is used in , But in the way we use it , Sometimes by calling the original message of the system , It will be easier to deal with , Especially in dealing with DLL File interaction , It's really very convenient .    stay C# Using custom messages in      ...

  5. Create simple and practical Thinkphp Page style (Bootstrap edition )

    First make complaints about it ThinkPHP3.1 Pagination style of version , Although it looks simple and generous , But all the page numbers are simple numbers , The gap between them is relatively small , It's not easy , And that “ front 5 page ” and “ after 5 page ” It's kind of redundant , Because clicking on the current page displays the first page ...

  6. In depth analysis of MFC -- The relationship between handle and object

    CWnd::FromHandlePermanent —— According to the window handle CWnd* The pointer This function, unlike FromHandle, does not create tempor ...

  7. Trees dp: Edge covering , Point coverage

    #493. Find the minimum dominating set of a tree Problem description For a tree n Rootless tree with nodes , Find its minimum dominating set . The minimum dominating set : It refers to taking as few points as possible from all vertices to form a set , So that all the rest of the points are connected with the edge of the point . The dominating set with the smallest number of vertices is ...

  8. Overclocking is really not difficult !G3258 Overclock 4.5GHz Total strategy

    Galloping G3258 With motherboard details [pconline application ] at present DIY The hottest installation combination in the market is Pentium 20 Anniversary processor G3258 collocation B85 Chipset motherboard , As long as through the appropriate overclocking , Relatively low investment can also provide a good performance experience ...

  9. MaxScript adopt .net Send E-mail

    Fn SmtpSendMail argSmtpAddress argSenderAddress argSenderPassword argTargetAddress argTitle argMessa ...

  10. mAP(mean Average Precision) application ( turn )

    The original address of the article comes from Zhihu :https://www.zhihu.com/question/41540197 1. precision and recall The calculation of ( There's nothing to say , The picture example is pretty good ): chart 1 Above in the picture ...