java.util.hashmap;import java.util.iterator;import Java.util.Map; Import java.util.set;/* * Map collection Traversal * Using keys to get values * Map Interface Definition Method keyset * All keys, stored in Set set */public class MapDemo1 {public S tatic void Main (string[] args) {/* * 1. Call the method of the Map collection keyset, all keys are stored in the Set collection * 2. Iterate through the set collection to get all the elements in the set set (the key in the map) * 3. Call the map set
variables.SummaryThere is nothing to say in this section, except to use iterations as much as possible in the N.O.P.E branch instead of recursion.7. Using EntrySet ()When we want to traverse a Map saved as a key-value pair, we have to find a good reason for the following code:Key:map.keySet ()) { value:map.get (key);}Let alone the following wording:For (EntryK key = Entry.getkey (); V value = Entry.getvalue ();} The map should be used with caut
for each key. Keyset (): After iteration, you can only fetch key through get ().
The result is random, because the Hashmap.keyset () method is used when the data row primary key is obtained, and this method returns the set result, in which the data is ordered to emit.
Typical uses are as follows:
Map map = new HashMap ();
Map.put ("Key1", "Lisi1");
Map.put ("Key2", "Lisi2");
Map.put ("Key3", "Lisi3");
Map.put ("Key4", "Lisi4");
Gets the set set of all the keys for the map Collection, keyset
the map, Map.entry is a key-value pair, and Map obtains Map.entry's key-value pairs by EntrySet (), which enables the operation of key-value pairs through the collection.
API for Map.entry
Abstract Boolean equals (object)Abstract K Getkey ()Abstract V GetValue ()abstract int hashcode ()Abstract v SetValue (V object)
3 Abstractmap
The definition of Abstractmap is as follows:
Public abstract class Abstractmap
The Abstractmap class provides the ba
First, Oracle: Stringsqlselect * from (selectt. *, rownumasnumfrom (select * fromuser1where11; SetEntryString, Objectsetm. entrySet (); Iteratorioset. iterator (); while (io. hasNext () {Map. entryString, Objectme (Map. en
First, Oracle: String SQL = select * from (select t. *, rownum as num from (select * from user1 where 1 = 1; SetEntryString, Object set = m. entrySet (); Iterator io = set. iterator (); w
Iterator function in Java is relatively simple and can only be moved one way:
(1) The method iterator () requires the container to return an Iterator. When the next () method of Iterator is called for the first time, it returns the first element of the sequence. Note: The iterator () method is a java. lang. Iterable interface inherited by Collection.
(2) Use next () to obtain the next element in the sequence.
(3) Use hasNext () to check whether there are any elements in the sequence.
(4) use re
This article will share with you a small feature that is needed in my personal project. it was implemented by du Niang after some time. now I will share it with you from the project. please refer to the required partners. A few days ago, the project wanted to use a map set of the same things. it took a while to get the object. today, I am idle to implement it.
Don't laugh
Code
Var Map = function () {/************ basic variable ***************/var hashmap = {}; var keys = []; var vals = []; va
This article will share with you a small feature that is needed in my personal project. It was implemented by Du Niang after some time. Now I will share it with you from the project. Please refer to the required partners. A few days ago, the project wanted to use a map set of the same things. It took a while to get the object. Today, I am idle to implement it.
Don't laugh
Code
Var Map = function () {/************ basic variable ***************/var hashmap = {}; var keys = []; var vals = []; va
an Iterator object, there must be a Collection object associated with it. When Iterator is used to iterate on the elements in the Set, Iterator does not pass the set element itself to the iteration variable, but the value of the Set element to the iteration variable, therefore, modifying the value of the iteration variable does not affect the set element.
2. There are two main ways to iterate the Map (key, value) set:
(1) Call the keySet and put it back into a Set set. The Set stores all the ke
/*** Keyset () iterator with map (low performance) **/ Public voidCompareMap1 () {MapNewHashmap//SmallmapNewHashmap//BigIteratorM1.keyset (). iterator (); while(Iter1.hasnext ()) {String M1key=(String) iter1.next (); if(!m1.get (M1key). Equals (M2.get (M1key))) {//if the value of the same key in the two map is not equal//...... } } } /*** Iterator with Map entryset () (High performance efficiency)*/ Public voidcompar
Are you tired of getting keywords from Map every time and getting the corresponding values? Using the Map. Entry class, you can get all the information at the same time. The standard Map access method is as follows: Set keys = map. keySet (); if (keys! = Null) {Iterator iterator = keys. iterator (); while (iterator. hasNext () {Object key = iterator. next (); Object value = map. get (key );;....;}} then there is a problem with this method. After obtaining keywords from Map, we must repeat the re
Abstractmap keyset,values, which are the collections used to traverse the map elements, and their main function is to output the data in the table by maintaining an iterator inside themselves. Key-value data is not actually stored.
MAP map = new hashmap At this point we'll calculate his occupancy:
total space is: 48+ 16=64 bytes
ha Shmap: Head (8) +int (4*4) +float (4) +table array Reference (4) +
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 future!
Second:
Map map = new hashmap ();
Iterator iter = map. keyset (). iterator ();
While (ITER. hasnext ()){
Object key = ITER. Next ();
Object val = map. Get (key );
}
is as follows:
The execution result is:
Key = Ture value = Ture
Map provides some common methods to retrieve the data in the Map, such as the entrySet () method. The returned value of entrySet () is a Set, the set type is Map. entry. Map. Entry is an internal interface declared by Map. This interface is generic and is defined as Entry
public static void main(String[] args) {Map
The execution r
Android submits data to the server in four ways
In Android application development, data is often submitted to the server and obtained from the server. This article mainly describes how to use the http protocol to submit data to the server in HttpClient mode.
/*** @ Author Dylan * This class encapsulates four methods for submitting data to the web server in Android */public class SubmitDataByHttpClientAndOrdinaryWay {/*** use get request submit data in Normal Mode * @ param map the data passed
System.out.println (array); 5 }It is important to note that the for-each is not intended to be used for adding or removing elements, which may be a little more concise if you are simply traversing the elements.(ii) Use of the iterator in the map interface:Use HashMap as an example to discuss two main ways of using iterators.1. The combination with the while () 1 hashmapnew Hashmap (); 2 // Omit the assignment procedure for MyMap 3 iterator.entryset (). iterator (); 4 while
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.