-What is HashMap:
A HashMap has value and key. store value based on Key. HasMap implements the Map interface and extends AbstractMap class.
Allow only one null as key and can contain multiple null value.
Also Conatin Order of element.
HasMap----extend---->AbstractMap----implement---->Map
Now we see how to Put and Retrive value from HashMap.
Example.
import java.util.*;
class MapTest{
public static void main(String args[]){
HashMap<Integer,String> map=new HashMap<Integer,String>();
map.put(1,"vjp");
map.put(13,"Vasant");
map.put(10,"anil");
for(Map.Entry m:map.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}
A HashMap has value and key. store value based on Key. HasMap implements the Map interface and extends AbstractMap class.
Allow only one null as key and can contain multiple null value.
Also Conatin Order of element.
HasMap----extend---->AbstractMap----implement---->Map
Now we see how to Put and Retrive value from HashMap.
Example.
import java.util.*;
class MapTest{
public static void main(String args[]){
HashMap<Integer,String> map=new HashMap<Integer,String>();
map.put(1,"vjp");
map.put(13,"Vasant");
map.put(10,"anil");
for(Map.Entry m:map.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}
-How Internally Working.
Example.
very nice explanation
ReplyDelete