The second question:public class person { private string name; public person () { } public person (String name) { super (); this.name = name; } public string getname () { return this.name; }}public Class dog { private string name; public dog () { } Public dog (string name) { super (); this.Name = name; } public string getname () { return this.name; }}import Java.util.map;import java.util.hashmap;import java.util.map.entry;import java.util.list;import java.util.arraylist;public class hashdemo { public static void main (String[] args) { map<person, Dog> hashmap = new hashmap<person,dog> (); List<Person> list = new ArrayList<Person> (); person person_obj = null; for (int i=0;i<100;i++) { person_obj = new person ("Person_name" + i); hashmap.put (Person_obj, new dog ("Dog_name" + i)); list.add (person_obj); } //keyset for (Person p : hashmap.keyset ()) { System.out.println (P.getname () + "---" + hashmap.get (P). GetName ()); } //EntrySet for (entry<person, Dog> entry : hashmaP.entryset ()) { system.out.println (Entry.getkey (). GetName () + "---" + entry.getvalue (). GetName ()); } for (person pl : list) { hashmap.remove (PL); } system.out.println ("------------"); System.out.println (Hashmap.size ()); }}
This article is from the "Forest Sensitive" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1774754
Big Data Java Foundation 11th day Job