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)