Java Collection (MAP)

Source: Internet
Author: User

-------------------| The data stored in the MAP is in the form of key-value pairs, the keys are not repeatable, and the values are repeatable.

----------------------------| HashMap

----------------------------| TreeMap

----------------------------| HashTable

Map interface methods:

Add to:
Put (K key, V value)
Putall (map<? extends K,? extends v> m)

Delete
Remove (Object key)
Clear ()

Get:
Get (Object key)
Size ()

Judge:
ContainsKey (Object key)
Containsvalue (Object value)
IsEmpty ()

ImportJava.util.*; Public classex12 { Public Static voidMain (string[] args) {Map<string, string> map =NewHashmap<string, string> ();//Why did you change to int ?Map.put ("Tom", "1"); Map.put ("Jack", "2"); Map.put ("Yoo", "3"); Map.put ("Peter", "4"); Map.put ("LiLi", "5");        SYSTEM.OUT.PRINTLN (map);        System.out.println (); Map<string, string> map2 =NewHashmap<string,string>(); Map2.put ("AAAAA", "1"); Map2.put ("Ppppp", "6"); Map.putall (MAP2);//Add all of the MAP2 to the map collectionSYSTEM.OUT.PRINTLN (map);//Note the result of the row outputSystem.out.println (); System.out.println ("Remove (Object key) =====" + map2.remove ("AAAAA"));//Note the return valueSystem.out.println ("Remove (Object key) =====" + map2.remove ("bbbbb"));        System.out.println (); //System.out.println ("Clear () =======" + map2.clear ());//Errormap2.clear (); System.out.println (MAP2);//Clear AllSystem.out.println (); System.out.println (Map.get ("PPPPP"));        System.out.println (Map.size ());        System.out.println ();            System.out.println (Map.isempty ()); }}

Java Collection (MAP)

Related Article

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.