map can be thought of as a collection of (Key,value). The map interface provides 3 types of collection views, a set of key collections, a set of value collections, or a set of key-value mapping relationships, from the contents of the map.Hashtable classHashtable inherits the map interface to implement a key-value mapped hash table. Any object that is not empty (
Java programming example code based on three algorithm questions of quick sorting, java example
Overview
Quick sorting is an update of the Bubble sorting we have learned before. They all belong to the exchange sorting class and are sorted by continuous comparison and movemen
temp:uniqueset) {System.out.println (temp + ":" + collections.frequency (list, temp));
} System.out.println ("\ n Example 3-the number of occurrences of the object is computed with a map"); Map map = new HashMap ();
for (String temp:list) {Integer count = map.get (temp);
Map.put (temp, (coun
Introduction to collection classes
The Java Collection class derives primarily from two interfaces:collection and Map, which also contain some interfaces or implementation classes.A collection represents a set of object, the collection element (Elements). Some collection allow the same elements while others do not. Some can be sorted and others not. The
Java class set framework simple comprehension of List, set, Iterator, map1. Java class set framework body structure:(1). Collection (SET): objects are not sorted by a particular time, and there are no duplicate objects.(2). List: objects are sorted by index location and can have duplicate objects.(3).
First, overview:By looking at the map interface description, we discover the collection under the map interface and the set under the collection interface, which store the data in different forms , such as.1. collections in Collection , where elements are isolated (understood as single), are stored in the same way as elements stored in the collection.2. The collection in
the java. util. comparator interface and implement the comare () method in this interface. Example above
4. Map Interface
Objects that implement the java. util. map interface map keys to values ). When saving an object to
Map InterfaceThe Map collection stores data in a key-value pair (Key-value) where the key cannot be duplicated and the value can be duplicated.Common classes are HashMap, TreeMap and propertiesHashMap classIf, now I have a collection that stores a batch of WiFi names and passwords, now requires a quick name to find the password. Such a requirement is very difficult to implement with the list collection, and
second list and comparer method to sort key or value, if the comparator returns 0, the value is the same as the reverse value, how much output. (If a friend knows why, please leave a message under the article, thank you)HashMap sortWe are all HashMap values are not sequential, he is based on key hashcode to achieve. How are we going to achieve this sort of unordered hashmap? Referring to the value of TreeMap, we can also implement HashMap sort.Sort by keyAs with TreeMap, the new treemapSort by
Java Map Traversal of a collection (brief)Let's share it today. Iterator traversal and enhanced for traversal for collections (take the map collection as an example)To everyone simple introduction to the map collection, the map co
objects in the set set are not sorted in a particular way, but simply add the object to the collection, but the Set collection cannot contain duplicate objects, and the set set has a set interface and a set interface implementation class composition. The set interface inherits the collection interface, so there are many ways to include the collection interface.The classes commonly implemented by the set interface are: Hashset and TreeSet classes? The
Specify the key in square brackets and return the corresponding value as the expression value. For example, expression $ {map ['key']} returns the value associated with the "key" key in the Map referenced by the map identifier.
When the expression value in the items attribute of foreach is
Specify the key in square brackets and return the corresponding value as the expression value. For example, expression $ {map ['key']} returns the value associated with the "key" key in the map referenced by the Map identifier.When the expression value in the items attribute of forEach is
First:
Map map = new hashmap ();
Iterator iter = map. entryset (). iterator ();
While (ITER. hasnext ()){
Map. Entry entry = (Map. Entry) ITER. Next ();
Object key = entry. getkey ();
Object val = entry. getvalue ();
}
High efficiency. You must use this method in the
TreeMap () Constructs a new, empty tree map using the natural order of the keys.TreeMap (comparatorConstructs a new, empty tree map that is sorted according to the given comparer.TreeSet ()Constructs a new empty set that is sorted according to the natural order of its elements.TreeSet (comparatorConstructs a new empty
The list, set, and map interfaces are frequently used in Java to summarize the followingTheir inheritance and implementation relationships are as follows:Collection├list│├linkedlist│├arraylist│└vector│└stack└setMap├hashtable├hashmap└weakhashmapAn excerpt from an article, reproduced http://blog.csdn.net/dotnetdesigner/archive/2007/11/08/1874605.aspxThe Collection interface collection is the most basic collec
only be traversed by iterator (). 2. Set and collection have identical interfaces. 3, List, you can use the Get () method to remove one element at a time. Use numbers to select one of a bunch of objects, get (0) .... (Add/get) 4, the general use of ArrayList. Use LinkedList to construct stack stacks, queue queues. 5, map with put (K,V)/get (k), you can also use ContainsKey ()/containsvalue () to check if it contains a key/value. hashmap will use the
value, be careful: the definition of the Equals and Hashcode methods is no longer explicit on such a mapping.
Map Interface:
Map provides a mapping of key to value. A map cannot contain the same key, and each key can map only one value. The map interface provides a view o
and collection have identical interfaces.3, List, you can use the Get () method to remove one element at a time. Use numbers to select one of a bunch of objects, get (0) .... (Add/get)4, generally use ArrayList. Use LinkedList to construct stack stacks, queue queues.5, map with put (K,V)/get (k), you can also use ContainsKey ()/containsvalue () to check if it contains a key/value.HashMap will use the object's hashcode to quickly find the key.6, the e
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.