. MODE_PRIVATE); SharedPreferences. editor editor = preferences. edit (); // The Map class provides a method called entrySet (), which returns a Map. object set after Entry instantiation. // Next, Map. the Entry class provides a getKey () method and a getValue () method. // Therefore, the above Code can be organized to better conform to the logic for (Map. entry
Entry: map. entrySet () {Strin
as follows:
Public interface Map
The interface has a values method. By calling this method, all values in the Map set can be returned. There is a keySet () method, and the key values in all maps can be obtained after the call; call the entrySet () method to obtain all key-value pairs in the Map and store them in the form of a Set. To better express the key-value, the interface also defines an Entry
Public class HashMap Some important variables a
Every time, forget ~~ Mark it. You forget it. Hahaha ~~
Ah, old, getting useless ~~
Bytes ---------------------------------------------------------------------------------------------
Private Static Map
Private Static Map
Private Static Map
Private Static Map
For (iterator it = projectipblackinfo. Get ("project1"). iterator (); it. hasnext ();){
System. Out. println (it. Next ());
}
For (iterator it = projectipmaskedinfo. entryset (). iterator ()
Map set:
This set stores key-value pairs. One-to-one storage. The key must be unique.
When there is a ing relationship between elements, consider creating a map set.
Method Abstract:
1. Add: if the same key is displayed when the key is added. Then the added value overwrites the corresponding value of the original key, and the put method returns the overwritten value.
Put (K key, V value)
Putall (Map
2. Delete
Clear ()
Remove (Object key)
3. Judgment
Containvalue (object value)
Containskey (Obj
.
"Because the set in the ing key must be unique, you can use set to support it. You can also delete an element from the view. At the same time, the value related to the keyword will be deleted from the source image, but you cannot add any element ."
Collection values (): returns the gallery of all values in the image.
"Because the set of ing values is not unique, you can use collection to support it. You can also delete an element from the view. At the same time, the value and its keyword will
is as follows:
Import Java. util. *; Class arraylisttest {// iteration output element public static void printelements (Collection e) {iterator iter = E. iterator (); While (ITER. hasnext () {system. out. println (ITER. next () ;}} public static void main (string [] ARGs) {/* // basic test arraylist Al = new arraylist (); Al. add ("Java"); Al. add ("arraylist"); Al. add ("test"); For (INT I = 0; I
(3)Hashset and hashmapHashset: implements the hash table of the Set interface, which is implement
Java 2's collections framework mainly includes two interfaces and their extensions and implementation classes: Collection interface and map interface. The difference between the two lies in that the former stores a group of objects, while the latter stores some key/value pairs.
PublicInterfaceJava. util. Map {
// Altering methodsPublicObject put (Object key, object value );PublicObject remove (Object key );PublicVoidPutall (Java. util. Map );PublicVoidClear ();
// Querying MethodsPublicObject g
shown in the preceding figure,
// If the number of elements in a division is greater than 2 and the sum of the first two elements is less than or equal to the third number,
// Merge the first two values of the Division, and the other values remain unchanged to generate a new division.
The Code is as follows:
Public static map getlist (int n ){Map If (n = 1 ){Map. Put ("1", "1 = ");Return map;}Map = getlist (n-1 );Map For (Map. Entry entry: map. entryset
Three ways to Traverse 1.keySet () 2.values () 3.entrySet () for mapThree ways to get set, you can use foreach or iterator, you cannot use for, because the data structure determines the Packagecom.fync.jsj.mapTemplate;Importjava.util.Collection;ImportJava.util.HashMap;ImportJava.util.Map;ImportJava.util.Map.Entry;ImportJava.util.Set;ImportOrg.junit.Before;Importorg.junit.Test; Public classmapcycle {Mapmap; //get the data ready.@Before Public voidTestD
The map is an interface in Java, and Map.entry is an internal interface to the map. The Java.util.Map.Entry interface is mostly used when traversing a Map .Map provides some common methods, such as KeySet (), EntrySet (), and so on , the KeySet () method return value is a collection of key values in map, and the return value of EntrySet () returns a set collection of type Map.entry. Map.entry is an internal
Collection is a single-column collection, and map is a double-row collection. It contains the Here are three ways to read: Keyset,valueset, and EntrySet.Keyset is the collection that gets all the keys. Valueset is to get all worthwhile collections. EntrySet is a collection of all entries, and entry is the meaning of each entry (the key and the value).The specific usage is:1 PackageJavastudy;2 3 Importjava.util.Collection;4 ImportJava.util.HashMap;5 I
overwritten after deposit. 3 Prints the data in the map collection in the specified form: 1. Define a container. The StringBuilder buffer can hold any data in the form of either the keyset method of the Map collection or the EntrySet method to get the key value in the Map collection or its mapping relationship to get the value in the Map collection through the keyset Get (key) method Or the EntrySet
Public static void main (string [] ARGs ){ Map Map. Put ("1", "value1 ");Map. Put ("2", "value2 ");Map. Put ("3", "value3 ");// The first type is commonly used. The second value is used.System. Out. println ("Traverse Key and value through map. keyset :");For (string key: map. keyset ()){System. Out. println ("Key =" + key + "and value =" + map. Get (key ));}// Type 2System. Out. println ("Traverse Key and value through map. entryset using iterator :"
==============Enhanced for LoopIts underlying implementation is the use of iterator.What containers can use enhanced for? -----------iterableThe disadvantage of enhanced for is that it can only be traversed and cannot be manipulated during traversal.Enhanced for formatFor (type reference: Container) {}--------------------------------------------About iterating over a collection.List1.Iterator2. Enhanced for3. General for4.ListIteratorSet1. Enhanced for2.IteratorMap1.keySet---Get a set view of al
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.