Java Basic Knowledge Enhancement Collection Framework note 58:map collection of Linkedhashmap class overview

Source: Internet
Author: User

1. Overview of the Linkedhashmap class

Linkedhashmap: A hash table of the map interface ( guaranteed uniqueness ) and a list of links ( guaranteed order ) are implemented with a predictable sequence of iterations.

2. code example:

1  Packagecn.itcast_03;2 3 ImportJava.util.LinkedHashMap;4 ImportJava.util.Set;5 6 /*7 * Linkedhashmap: is the hash table and link list implementation of the map interface, with a predictable iteration order. 8 * guaranteed uniqueness of keys by hash table 9 * The chain list ensures that the keyboard is ordered (  The order of storage and removal is consistent) Ten  */ One  Public classLinkedhashmapdemo { A      Public Static voidMain (string[] args) { -         //To create a collection object -Linkedhashmap<string, string> HM =NewLinkedhashmap<string, string>(); the  -         //Creating and adding elements -Hm.put ("2345", "Hello"); -Hm.put ("1234", "World"); +Hm.put ("3456", "Java"); -Hm.put ("1234", "Java ee"); +Hm.put ("3456", "Android"); A  at         //Traverse -Set<string> set =Hm.keyset (); -          for(String key:set) { -String value =Hm.get (key); -SYSTEM.OUT.PRINTLN (key + "---" +value); -         } in     } -}

Run the effect as follows:

Basic knowledge of Java Collection Framework Notes 58:map collection Linkedhashmap class overview

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.