Overview:
Basic Features:
The collection stores key-value pairs and guarantees the uniqueness of the keys
Sub-class:
The |--hashtable is a hash data table structure and cannot use NULL as a key or value; The collection thread is synchronous
The |--hashmap is a hash data table structure that can use NULL as a key or value, and the collection thread is not synchronized
|--treemap Bottom is a two-fork tree structure, the thread is not synchronized, you can sort the key values in the map
Two ways to take out a map collection (principle: Convert the Map collection to set, and then use an iterator)
1. Incoming Map Collection
Public static map Sortbycomparator (map Unsortmap) {
List List = new LinkedList (Unsortmap.entryset ());
//System.out.println ("list:" +list);
Collections.sort (list, new Comparator ()
{
public int Compare (object O1, Object O2)
{
return ((comparable) ((Map.entry) (O2)). GetValue ())
. CompareTo (((map.entry) (O1)). GetValue ());
}
});
Map sortedmap = new Linkedhashmap ();
For (Iterator it = List.iterator (); It.hasnext ();) {
map.entry Entry = (map.entry) it.next ();
Sortedmap.put (Entry.getkey (), Entry.getvalue ());
}
return sortedmap;
}
Sort the map collection by value from large to small