Map of the Java Collection framework

Source: Internet
Author: User
Tags set set

Map of the Java Collection framework.

The main implementation classes of map are Hashmap,linkedhashmap,treemap, and so on. Refer to the API documentation for details.

Where HashMap is unordered ordering.

Linkedhashmap is a natural sort, first-time mapping.

The TREEMAP key cannot be null, but the value can be null,treemap the same as the data type of the key.

Hashtable keys and values are not nullable.

Here's a bit of code to feel.

          Map map = Newhashmap ();               Map.put (1, "a");        Map.put (2, "B");        Map.put (3, "C");        Map.put (nullnull);        Map.put (null, "D");         // hashmap keys and values can be null         // to make a collection   of key values

In map, find a Get method, inside is the key value of the object collection, the Map.keyset () method will return the collection of key values.

Set set = Map.keyset (); // Set the key value as a collection                = Set.iterator (); // constructs an iterator         while (It.hasnext ()) {// to determine if there are elements, returned as Boolean             System.out.println (Map.get (It.next ())); // if the key is the same, the value is overwritten         }

The output is: D

A

B

C

When the key is converted to the set set, NULL is the same, so within set, the first null object is overwritten by the second null object and HashMap is unordered.

Hashmap,linkedhashmap,treemap and so on. Map implementations are similar.

Map of the Java Collection framework

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.