"Java" Map

Source: Internet
Author: User

Today using the key-value pairs, and then think of the Java Map, because it was not very familiar with, looked at the following source code, as follows:

/** Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE proprietary/confidential. Use are subject to license terms. */ PackageJava.util; Public InterfaceMap<k,v> {    //Query Operations    intsize (); BooleanIsEmpty (); BooleanContainsKey (Object key); BooleanContainsvalue (Object value);    V get (Object key); //modification Operationsv put (K key, v value);    V Remove (Object key); //Bulk Operations    voidPutall (map<?extendsK?extendsV>m); voidClear (); // viewsSet<k>KeySet (); Collection<V>values (); Set<map.entry<k, v>>EntrySet (); InterfaceEntry<k,v>{K getKey ();        V GetValue ();        V SetValue (v value); Booleanequals (Object O); inthashcode (); }    //Comparison and hashing    Booleanequals (Object O); inthashcode ();}

PS: It is clear that the map is an interface, and HashMap is a class that implements the map interface. And I think the source code is very beautiful! You should look more later.

version:jdk1.7.0_79

MAP traversal, sample code:

Iterator entries = ReadFile.map.entrySet (). Iterator ();  while (Entries.hasnext ()) {    = (map.entry) Entries.next ();     = (String) Entry.getkey ();     = (String) entry.getvalue ();    System.out.print ("key:" + key + "," + "value:" + value + "\ n");}

Reference: Simple use of map,set in Java

"Java" Map

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.