In the Java world, all things are objects, then map is an interface! haha
As an example:
map<user,string> map=New Hashmap<user, string> ();
where the user class
PackageCom.map; Public classUser {Private intAge ; PrivateString name; Public intGetage () {returnAge ; } PublicUser () {Super(); } /** * * @paramAge *@paramname*/ PublicUser (intage,string name) { Super(); This. age=Age ; This. name=name; } Public voidSetage (intAge ) { This. Age =Age ; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } @Override Public inthashcode () {System.out.println ("Running the Hashcode"); Final intPrime = 31; intresult = 1; Result= Prime * result +Age ; Result= Prime * result + ((name = =NULL) ? 0: Name.hashcode ()); returnresult; } @Override Public Booleanequals (Object obj) {if( This==obj)return true; if(obj = =NULL) return false; if(GetClass ()! =Obj.getclass ())return false; User Other=(User) obj; if(Age! =other.age)return false; if(Name = =NULL) { if(Other.name! =NULL) return false; } Else if(!name.equals (other.name))return false; return true; } }
Run
PackageCom.map;ImportJava.util.HashMap;ImportJava.util.Iterator;ImportJava.util.Map; Public classMaptest { Public Static voidMain (string[] args) {//TODO auto-generated Method StubUser user=NewUser (10, "Xiaoming"); User User1=NewUser (12, "Xiao Li"); Map<User,String> map=NewHashmap<user, string>(); Map.put (User,"Xiao Ming"); Map.put (User1,"KK"); Iterator<User> iter=Map.keyset (). iterator (); while(Iter.hasnext ()) {User User2=Iter.next (); String name=Map.get (User2); } }}
Get output
Ran the hashcode ran the hashcode
Hashmap--hash is a method that every object has.
The default length of the map is 16, and the hash value of the key gets its position. If the value is the same, it is placed behind the previous value and is a linked list structure
Using debug mode, selecting "View" (watch) will get
Map has a number of implementation classes, Concurrenthashmap, Hashtable, HashMap,
Reference: http://blog.csdn.net/renfufei/article/details/17287729
Java Basic Note--map