Java Mapping (Map usage)

Source: Internet
Author: User

Two main interfaces: collection and map
Three main categories: collection (set), list, mapping (map)
1. Collection: No duplicate objects, no specific sort method
2. List: objects are sorted by index location and can have duplicate objects
3. Mapping: There is a key object and a value object, the key is not repeatable, the value can be repeated

Hashtable and HashMap differences

1 HashMap is not thread-safe

2 Hashtable is a thread-safe collection.

Hastmap is an interface that is a sub-interface of the map interface, an object that maps keys to values, where the keys and values are objects and cannot contain duplicate keys, but can contain duplicate values. HashMap allows null key and null value, while Hashtable is not allowed.

public class Main {public static void main (String args []) {//Declaration mapmap<string,string> Ma=new Hashmap<string,stri Ng> ();//Store Data Ma.put ("1", "a") in the map, Ma.put ("2", "B"), Ma.put ("1", "C");//overwrite the first value//Get map size ma.size ();// Get map Data Ma.get ("1");}}

  

Java Mapping (Map usage)

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.