1 Packagemap_show;2 /*3 * Map--properties4 */5 6 7 8 /*9 * Map Interface: A collection of "key-value pairs" with a mapping relationship---similar to high school "functions"Ten * One *------Map Method: A * - ? Add, delete operations: - ---> Object put (object Key,object value) associates the specified value with the specified key in this map the void Putall (Map t) - Example: Map.put ("AA", one-to-one); - ---> Object Remove (Object key) - ? void Clear () + - ? Ways to manipulate meta view: + ---> Set keySet () returns a set view of the keys contained in this map. A Example: Set KeySet = Map.keyset ();//means to take out all the keys at ---> Collection values () returns the Collection view of the values contained in this map. - Example: Collection Collection = Map.values ();//means to take out all the value - ---> Set entryset () returns a set view of the mapping relationships contained in this map. - Example: Set entryset = Map.entryset ();//Show All mapped pairs: aa=11 description: Mainly K, can be map.get (k), to get v - ? - element query operation: in ---> Object get (Object key) - ? Boolean ContainsKey (Object key) to ? Boolean Containsvalue (Object value) + ---> int size () - ? Boolean isEmpty () the ? Boolean equals (Object obj) * $ the Map.entry interface has Getkey () GetValue () to obtain the corresponding K VPanax Notoginseng Example: Itarator iter=map.entryset (). Itarator (); - ---> Map.entry Entry = (Entry) iter.next (); the ---> System.out.println (entry.getkey () + "--->" +entry.getvalue ()); + A the + implementation Class of Map interface HashMap TreeMap Properties - $ $ - - the (extension): public class Hashtable<k,v>extends dictionary<k,v> - implements Map<k,v>, cloneable, SerializableWuyi (HashMap and Hashtable) the Hashtable: Old, thread-safe does not allow NULL as K, V - HashMap: Thread unsafe allow null Wu - About Properties Class: $ inherit from Hashtable, so there are k/v are strings; Mainly used in property files or configuration files - Description: - 1, because the property file key, value is a string type, so the properties of the key and value are string types - 2. When accessing data, it is recommended to use the SetProperty (string key,string value) method and the GetProperty (string key) method A Example: + There is a file: the full file name: config.properties: - File Contents: $ userName hehe the Password 123 the Code-----: the Properties Pro=new properties (); the ---> Pro.load (New FileInputStream ("D:/config.properties" )); - ---> String name=pro.getproperty ("UserName"); Get v through K in String pwd=pro.getproperty ("password"); the System.out.println ("User name:" +name+ "Password:" +pwd); the Result-----: About user name: hehe password: 123 the the the + */ - Public classMap_method { the Bayi}
Java Basic Note--map